Python Practice › Pandas Programs › Program 46

Add a column

EasyPandas Programs · 46 of 95

Write a pandas program to add a salary column.

Advertisement
Output
    name  age  salary
0   Alex   30   50000
1   John   27   65000
2  Peter   29   58000
3  Klaus   33   66000

Approach

  1. Assign a list to a new column name.

Solution

Python
import pandas as pddf = pd.DataFrame({"name": ["Alex", "John", "Peter", "Klaus"], "age": [30, 27, 29, 33]})df["salary"] = [50000, 65000, 58000, 66000]print(df)
Output
    name  age  salary
0   Alex   30   50000
1   John   27   65000
2  Peter   29   58000
3  Klaus   33   66000
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More pandas programs

← All 95 Pandas Programs