- API reference
- Series
- pandas.Serie...
pandas.Series.to_dict#
- Series.to_dict(*,into=<class'dict'>)[source]#
Convert Series to {label -> value} dict or dict-like object.
- Parameters:
- intoclass, default dict
The collections.abc.MutableMapping subclass to use as the returnobject. Can be the actual class or an empty instance of the mappingtype you want. If you want a collections.defaultdict, you mustpass it initialized.
- Returns:
- collections.abc.MutableMapping
Key-value representation of Series.
Examples
>>>s=pd.Series([1,2,3,4])>>>s.to_dict(){0: 1, 1: 2, 2: 3, 3: 4}>>>fromcollectionsimportOrderedDict,defaultdict>>>s.to_dict(into=OrderedDict)OrderedDict([(0, 1), (1, 2), (2, 3), (3, 4)])>>>dd=defaultdict(list)>>>s.to_dict(into=dd)defaultdict(<class 'list'>, {0: 1, 1: 2, 2: 3, 3: 4})
On this page