MediumPython Add List to Existing DataFrame | by Zeeshan Ali | Medium
Sitemap
Zeeshan Ali

Zeeshan Ali

I am a Python developer and I am here to share what i have learnt so far. Hope my posts will help you in your python development journey. www.letmeflutter.com

Python Add List to Existing DataFrame

1 min readJul 14, 2023

To add a list to an existing dataframe in Python, you can use the Pandas library. Here’s an example of how you can do it:

import pandas as pd
# Create an existing dataframe
data = {'Name': ['John', 'Emma', 'Ryan'],
'Age': [25, 28, 30]}
df = pd.DataFrame(data)
# Create a list to add to the dataframe
new_list = ['USA', 'Canada', 'UK']
# Add the list as a new column to the dataframe
df['Country'] = new_list
# Print the updated dataframe
print(df)

Output:

Name  Age Country
0 John 25 USA
1 Emma 28 Canada
2 Ryan 30 UK

In this example, we first create an existing dataframe with columns “Name” and “Age”. Then, we define a new list called new_list containing the values we want to add to the dataframe. Finally, we add the new list as a new column called "Country" using the square bracket notation df['Country'] = new_list. The resulting dataframe will contain the original columns along with the new "Country" column.

Get Zeeshan Ali’s stories in your inbox

Join Medium for free to get updates from this writer.

Click here to get more tutorials on Python lists.

--

--

Zeeshan Ali
Zeeshan Ali

Written by Zeeshan Ali

I am a Python developer and I am here to share what i have learnt so far. Hope my posts will help you in your python development journey. www.letmeflutter.com