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 Aug 17 2026
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 pddf = pd.DataFrame({"A": [1, 2, 3]})df["B"] = 10print(df)Output:
A B0 1 101 2 102 3 10Assigning a list or array
- Assign different values per row (length must match number of rows).
df["C"] = [100, 200, 300]print(df)Output:
A B C0 1 10 1001 2 10 2002 3 10 300Using calculations on existing columns
- New columns can be derived from existing ones.
- Changes the original DataFrame.
df["D"] = df["A"] + df["C"]print(df)Output:
A B C D0 1 10 100 1011 2 10 200 2022 3 10 300 303Using .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)Using .insert()
- Insert a column at a specific position.
# insert at index 1df.insert(1, "F", [7, 8, 9]) print(df)Output:
A F B C D E0 1 7 10 100 101 2021 2 8 10 200 202 4042 3 9 10 300 303 606Dropping 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 columnsDrop multiple columns::
df.drop(["C", "D"], axis=1, inplace=True)Key parameters:
axis=1→ columnsaxis=0→ rows (default)inplace=True→ modify the DataFrame directly
Using del
- Deletes a single column.
del df["F"]Using .pop()
- Removes a column and returns it.
popped_column = df.pop("E")print(popped_column)