Pandas Series from Dictionary


This entry is part 3 of 4 in the series pandas Series

If you have a Python dictionary, can you use that to create a pandas Series? Yes. You use the pandas.Series() function. Likely you will be using an alias. Suppose your dictionary is called dict. The code would be series1 = pd.Series(dict).

We’ll create a dictionary.

import pandas as pd
# create a dictionary
medals = {
    'First': 'Gold',
    'Second': 'Silver',
    'Third': 'Bronze'
}
medals

The output is:

{'First': 'Gold', 'Second': 'Silver', 'Third': 'Bronze'}
ser = pd.Series(medals)
ser

The output is.

First       Gold
Second    Silver
Third     Bronze
dtype: object

Get the values

ser.values
array(['Gold', 'Silver', 'Bronze'], dtype=object)
Series Navigation<< Pandas Series from a DataFrameCreate a Set from a Pandas Series >>

Leave a Reply