- Pandas Series Introduction
- Pandas Series from a DataFrame
- Pandas Series from Dictionary
- Create a Set from a 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)