🔵 🔵 🔵


Primary

၊၊||၊|။

Series.to_dict() ⚬|Documentation|1st|20251021002607-00-⌔

pandas.Series.to_dict — pandas 2.3.3 documentation#pandas.Series.to_dict

class Series.to_dict(﹡, into=<'dict'>)

Convert Series to {label -> value} dict or dict-like object.

Parameters:
into: class, default dict

The collections.abc.MutableMapping subclass to use as the return object. Can be the actual class or an empty instance of the mapping type you want. If you want a collections.defaultdict, you must pass it initialized.

Returns:
collections.abc.MutableMapping

Key-value representation of Series.

See also:
Series.to_list

Converts Series to a list of the values.

Series.to_numpy

Converts Series to NumPy ndarray.

Series.array

ExtensionArray of the data backing this Series.

Examples:
>>> 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(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})

Printed 2026-06-28.

(echo:: @ )

Link to original

Secondary

• • •