Pandas Data Series: Convert a dictionary to a Pandas series

Pandas: Data Series Exercise-5 with Solution

Write a Pandas program to convert a dictionary to a Pandas series.

Sample dictionary: d1 = {'a': 100, 'b': 200, 'c':300, 'd':400, 'e':800}

Sample Solution :

Python Code :

import pandas as pd
d1 = {'a': 100, 'b': 200, 'c':300, 'd':400, 'e':800}
print("Original dictionary:")
new_series = pd.Series(d1)
print("Converted series:")

Sample Output:

Original dictionary:
{'a': 100, 'b': 200, 'c': 300, 'd': 400, 'e': 800}
Converted series:
a    100
b    200
c    300
d    400
e    800
dtype: int64                                 

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Pandas program to compare the elements of the two Pandas Series.
Next: Write a Pandas program to convert a NumPy array to a Pandas series.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz

Python: Tips of the Day

Returns a list with n elements removed from the beginning


def tips_take(itr, n = 1):
  return itr[:n]
print(tips_take([1, 2, 3], 5))
print(tips_take([1, 2, 3], 0))


[1, 2, 3]