Dictionary to Series

EasyPandas Programs · 9 of 95

Write a pandas program to convert a dictionary to a Series.

Advertisement
Input
{"name": "Virat", "sport": "cricket", "age": 32}
Output
name       Virat
sport    cricket
age           32
dtype: object

Approach

  1. Keys become the index.

Solution

Python
import pandas as pdprint(pd.Series({"name": "Virat", "sport": "cricket", "age": 32}))
Output
name       Virat
sport    cricket
age           32
dtype: object
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More pandas programs

← All 95 Pandas Programs