📜  熊猫系列到字典 python 代码示例

📅  最后修改于: 2022-03-11 14:45:56.572000             🧑  作者: Mango

代码示例1
>>> s = pd.Series([1, 2, 3, 4])
>>> s.to_dict()
{0: 1, 1: 2, 2: 3, 3: 4}
>>> from collections import OrderedDict, defaultdict
>>> s.to_dict(OrderedDict)
OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)])
>>> dd = defaultdict(list)
>>> s.to_dict(dd)
defaultdict(, {0: 1, 1: 2, 2: 3, 3: 4})