Adding and Dropping Columns
Pandas Basics
1 min read
This section is 1 min read, full guide is 30 min read
Published Sep 29 2025, updated Oct 24 2025
21
Show sections list
0
Log in to enable the "Like" button
0
Guide comments
0
Log in to enable the "Save" button
Respond to this guide
Guide Sections
Guide Comments
PandasPython
Adding columns
There are various ways you can add new columns to a DaraFrame.
Assign the same value to every row
import pandas as pd
df = pd.DataFrame({"A": [1, 2, 3]})
df["B"] = 10
print(df)
Copy to Clipboard
Output:
A B
0 1 10
1 2 10
2 3 10
Copy to Clipboard
Assigning a list or array
- Assign different values per row (length must match number of rows).
df["C"] = [100, 200, 300]
print(df)
Copy to Clipboard
Output:
A B C
0 1 10 100
1 2 10 200
2 3 10 300
Copy to Clipboard
Using calculations on existing columns
- New columns can be derived from existing ones.
- Changes the original DataFrame.
df["D"] = df["A"] + df["C"]
print(df)
Copy to Clipboard
Output:
A B C D
0 1 10 100 101
1 2 10 200 202
2 3 10 300 303
Copy to Clipboard
Using .assign()
- Creates a new column (or multiple) without modifying the original.
- Can also be chained together.
df = df.assign(E=df["D"] * 2)
print(df)
Copy to Clipboard
Using .insert()
- Insert a column at a specific position.
# insert at index 1
df.insert(1, "F", [7, 8, 9])
print(df)
Copy to Clipboard
Toggle show comments
Output:
A F B C D E
0 1 7 10 100 101 202
1 2 8 10 200 202 404
2 3 9 10 300 303 606
Copy to Clipboard
Dropping columns
There are also various ways you can remove columns from a DataFrame.
Using .drop()
- Drops columns by name.
df.drop("B", axis=1, inplace=True) # axis=1 for columns
Copy to Clipboard
Drop multiple columns::
df.drop(["C", "D"], axis=1, inplace=True)
Copy to Clipboard
Key parameters:
axis=1→ columnsaxis=0→ rows (default)inplace=True→ modify the DataFrame directly
Using del
- Deletes a single column.
del df["F"]
Copy to Clipboard
Using .pop()
- Removes a column and returns it.
popped_column = df.pop("E")
print(popped_column)
Copy to Clipboard














