Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Convert Between a Pandas.Series and a Dict-Like Object

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

import pandas as pd

Series to dict

s = pd.Series(["how", "are", "you"])
s
0 how 1 are 2 you dtype: object
s.to_dict()
{0: 'how', 1: 'are', 2: 'you'}

dict to Series

dic = {"how": 0, "are": 2, "you": 1}
dic
{'how': 0, 'are': 2, 'you': 1}
pd.Series(dic)
how 0 are 2 you 1 dtype: int64