Thuta Learning
IntermediateData & Databasesintermediate

Dropping Rows & Columns

Relax. We'll talk through this in plain words — no textbook voice.

Dropping Rows & Columns

If your data has columns you don't need for analysis, test rows, or duplicate-looking temporary fields, you can remove them with .drop(). To drop a column, use axis=1, and to drop a row, use the index.

python
import pandas as pd

df = pd.DataFrame({
    "Name": ["Alice", "Bob", "Charlie"],
    "Age": [25, 30, 35],
    "City": ["New York", "Paris", "London"],
    "TempNote": ["ok", "check", "old"]
})

clean_df = df.drop("TempNote", axis=1)
without_first_row = clean_df.drop(0, axis=0)

print(clean_df)
print("
After dropping first row:")
print(without_first_row)

df.drop("TempNote", axis=1) drops the column. clean_df.drop(0, axis=0) drops the row at index 0. Since we save the resulting DataFrame into a new variable after dropping, the original df stays untouched.

You should see
Name Age City 0 Alice 25 New York 1 Bob 30 Paris 2 Charlie 35 London After dropping first row: Name Age City 1 Bob 30 Paris 2 Charlie 35 London

Info

If you want to change the original DataFrame directly, you can use inplace=True, but for beginners it's safer to save into a new variable — if you make a mistake, the original data is still sitting there safe and sound.

Dropping Rows & Columns | Thuta Learning