Python Add List to Existing DataFrame
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 UKIn 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.






