logo

Adding New Columns

Adding a column is as simple as assigning to a new column name.

With a constant value:

df['country'] = 'USA'

Every row gets the same value.

With a list (must match row count):

df['scores'] = [85, 92, 78, 88]

From another column:

df['name_upper'] = df['name'].str.upper()

The new column appears at the end. If you assign to an existing column name, it overwrites the old values.

I cover column operations comprehensively in my Pandas course.