Introduction to Pandas
Chapter 2: Series
Creating a Series instance
Your data
can also be a Python dict
. The dict
keys will automatically be used as the index
.
>>> series = pd.Series(data={"a": "UK", "b": "France", "c": "Italy"})
>>> print(series)
a UK
b France
c Italy
dtype: object
If you provide an index
, then pandas will attempt to match the indices to your dict
keys, and use the corresponding values as the data
instance.
>>> series = pd.Series(data={"a": "UK", "b": "France", "c": "Italy"},
... index=["b", "c", "d", "a"])
>>> print(series)
b France
c Italy
d NaN
a UK
dtype: object