Pandas DataFrame

Does assign data to any DataFrame with a nonexisting column name create a new column?

The following code adds a new column, capital, to an existing DataFrame in Pandas.

import pandas as pd

dict = {"country": ["France", "Italy", "Turkey", "Thailand"] }

capital = ['Paris', 'Rome', 'Istanbul', 'Bangkok']

data = pd.DataFrame(dict)


data['capital'] = capital


Thank you again for reaching out! Please feel free to reach out if you have any other queries or concerns.

Best Regards,
Hiba Khurshid | Developer Advocate
Educative Inc.

1 Like