How to Create Pandas Series from a List (with example)

You can create Pandas Series from a list using this syntax:

pd.Series(list_name)

In the next section, you’ll see the steps to apply the above syntax using a simple example.

Steps to Create Pandas Series from a List

Step 1: Create a List

To start, let’s create a list that contains 5 names:

people_list = ['Jon','Mark','Maria','Jill','Jack']
print(people_list)

This is how the list would look like:

Example of Python List

The ultimate goal is to create a Pandas Series from the above list.

Step 2: Create the Pandas Series

Next, create the Pandas Series using this template:

pd.Series(list_name)

For our example, the list_name is “people_list.” Therefore, the complete code to create the Pandas Series is:

import pandas as pd

people_list = ['Jon','Mark','Maria','Jill','Jack']

my_series = pd.Series(people_list)

print(my_series)

Once you run the code in Python, you’ll get the following Series:

How to Create Pandas Series from a List

Step 3 (optional): Verify that you Created the Series

You can quickly verify that you successfully created the Pandas Series by adding “print(type(my_series))” to the bottom of the code:

import pandas as pd

people_list = ['Jon','Mark','Maria','Jill','Jack']

my_series = pd.Series(people_list)

print(my_series)

print(type(my_series))

Run the code, and you’ll be able to confirm that you got the Pandas Series:

How to Create Pandas Series from a List

Change the Index of Pandas Series

You may have noticed that each row is represented by a number (also known as the index) starting from 0:

Example of index

Alternatively, you may assign another value/name to represent each row. For example, in the code below, the index=[‘A’,’B’,’C’,’D’,’E’] was added:

import pandas as pd

people_list = ['Jon','Mark','Maria','Jill','Jack']

my_series = pd.Series(people_list, index=['A','B','C','D','E'])

print(my_series)

You’ll now see the newly assigned values:

Change index

Additional Resources

So far, you have seen how to create Pandas Series. You may also want to check the following guide to learn how to create Pandas DataFrame.

Finally, you can learn more about Pandas Series by visiting the Pandas Documentation.