New to Rust? Grab our free Rust for Beginners eBook Get it free →
df.drop in pandas: 5 ways to drop one or more columns

Removing unwanted columns is one of the first cleanup steps in almost any pandas workflow, and df.drop() is the method built for the job. It lets you remove columns or rows by name, index position or label range, and it works the same way on a DataFrame loaded from a CSV file or built by hand. This guide covers five practical ways to drop columns, plus how the same method handles rows, errors and multi-level indexes.
Syntax and parameters of df.drop() in pandas
Every example in this guide calls df.drop() with slightly different arguments, so it helps to see the full signature before you get to them. The method looks like this:
DataFrame.drop(labels=None, axis=0, index=None, columns=None, level=None, inplace=False, errors='raise')
Parameters:
- labels: single label or list of labels to drop. Works with axis to decide rows or columns.
- axis: 0 (or ‘index’) drops rows, 1 (or ‘columns’) drops columns. Defaults to 0.
- index: alternative to labels with axis=0. Pass row labels directly.
- columns: alternative to labels with axis=1. Pass column names directly.
- level: for a MultiIndex DataFrame, sets which level the labels belong to.
- inplace: False returns a new DataFrame. True changes the original DataFrame and returns None.
- errors: ‘raise’ (default) throws a KeyError for a missing label. ‘ignore’ skips it quietly.
The columns parameter is usually the cleanest way to drop columns since it skips the axis argument entirely. df.drop(columns=['size']) and df.drop(['size'], axis=1) do exactly the same thing.
Dropping columns from Pandas DataFrame in Python
For Dropping columns from the DataFrame let’s first create a DataFrame using a CSV file.
Example:
import pandas as pd
df = pd.read_csv('Bengaluru_House_Data.csv')
print(df)
Here we have first imported pandas as pd then created the DataFrame using a CSV file Bengaluru_House_Data.csv and after that, we printed the DataFrame.
Output:

The five ways to drop columns from a Pandas DataFrame are:
1. Dropping columns from a DataFrame using drop()
We can drop a single column as well as multiple columns directly using the drop( ) method.
Example 1:
In this example, we will drop a single column which is size column from the DataFrame.
import pandas as pd
df = df.drop(['size'], axis = 1)
print(df)
Here we have used a function df.drop and inside it, we have defined a list in which we have defined the column name and we have taken the column size to drop. Then we have defined the axis as 1, axis=1 means for columns. Then after running, the size column will be removed from the DataFrame.
Output:

Example 2:
In this example, we will drop multiple columns from the DataFrame.
import pandas as pd
df = df.drop(['size','location'], axis = 1)
print(df)
For dropping multiple columns we have provided the column names which are location and size in the drop() function inside a list. After running the above code, the size and location column will be dropped from the DataFrame.
Output:

2. Dropping columns from DataFrame using drop() based on column indices
We can drop columns from DataFrame with the help drop() method and the indices of the columns.
Example:
import pandas as pd
df = df.drop(df.columns[[2,3]],axis =1)
print(df)
Here we have dropped the location and size columns having index 2 and 3. After running the above code, the size and location columns will be dropped.
Output:

3. Dropping columns from a DataFrame using drop() with iloc[]
We can drop columns from the DataFrame using the drop( ) method and iloc[ ] together.
Example:
import pandas as pd
df = df.drop(df.iloc[:,2:4],axis =1)
print(df)
Here we have first written the function df.drop( ) and passed df.iloc[ ] as an argument inside which we have to write what we wanted to drop. We wanted to delete some columns and all the rows of those columns. In iloc[ ] first parameter is for rows and the second parameter is for columns. For rows, we wanted to delete all rows that’s why it will be a single colon (:) and we have to provide a second parameter for the column that’s why we used commas to separate it. Since we wanted to remove the location and size columns, we have to pass index 2 to 4 as 4 will not be taken. After running the above code, the size and location columns will be dropped from the DataFrame.
Output:
![Dropping Columns from a DataFrame Using drop( ) with iloc[] Output](https://codeforgeek.com/wp-content/uploads/2023/08/Screenshot-1636.png)
4. Dropping columns from a DataFrame using drop() with loc[]
We can also drop columns from the DataFrame using drop( ) and loc[ ] together. loc[ ] is the same as iloc[ ], the difference is we have to define the column name here rather than the index.
Example:
import pandas as pd
df = df.drop(df.loc[:,'availability':'society'].columns, axis =1)
print(df)
Here we have used df.drop( ) and passed df.loc[ ], we have defined the column name availability and society to drop. After running the above code, all the columns between these columns will be dropped.
Output:
![Dropping Columns from a DataFrame Using drop() with loc[] Output](https://codeforgeek.com/wp-content/uploads/2023/08/Screenshot-1637.png)
5. Dropping columns from a DataFrame in iterative way
This is the last method for dropping columns from the DataFrame which will use del and for loop hence it is called the iterative way of deleting the columns.
Example:
import pandas as pd
for col in df.columns:
if 'size' in col:
del df[col]
print(df)
Here we ran a for loop which iterated over all the columns and then we defined the column name as size. Then we wrote if ‘size’ in col: after that del df[col] means we have iterated over all the columns and if found the size column we have to delete that column. In last we have printed the DataFrame that is df.
After running the above code, we have seen that the size column is removed and changes have come to our original DataFrame.
Output:

Note: In the previous methods, the size column was present in the original DataFrame after applying those methods but now in this method, we have seen that the size column is not there in the original DataFrame anymore so that means that this last method changes the original DataFrame.
How to drop rows with df.drop()
df.drop() also removes rows, not just columns. Set axis=0 (the default) or use the index parameter, and it removes rows by their label instead.
import pandas as pd
data = {'name': ['Asha', 'Ravi', 'Meera'], 'age': [28, 34, 41], 'city': ['Pune', 'Delhi', 'Pune']}
df = pd.DataFrame(data)
df_rows_dropped = df.drop(index=1)
print(df_rows_dropped)
This removes the row at index 1, which is Ravi’s record, and leaves Asha and Meera untouched. Pass a list, df.drop(index=[0, 2]), to remove more than one row at once. Row labels do not have to be plain integers either. If you set a custom string index with set_index(), drop() removes rows by that label just as easily.
Dropping rows works well when you already know exactly which labels to remove. If the rows you want gone depend on a condition instead of a fixed label, filtering the DataFrame or the query() method is usually a shorter path since you skip the step of looking up index positions first.
How to handle missing columns with the errors parameter
By default, df.drop() raises a KeyError the moment it hits a label that does not exist in the DataFrame. That is often exactly what you want, since a typo in a column name should not fail silently.
import pandas as pd
df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
# raises KeyError because 'C' does not exist
df.drop(columns=['C'], errors='raise')
Set errors='ignore' when the column may or may not be present, for example when a script runs against DataFrames built from different sources.
df_safe = df.drop(columns=['C'], errors='ignore')
print(df_safe)
This version runs without raising anything and returns the DataFrame unchanged if the column was already missing. That single line often fixes scripts that break intermittently across data sources with slightly different schemas. If errors behaves differently than you expect, it is worth confirming your installed pandas version first, since parameter defaults have shifted across major releases.
Dropping labels from a MultiIndex DataFrame
A MultiIndex DataFrame has more than one level of row labels, which is common after a groupby or a pivot. df.drop() handles this case with the level parameter.
import pandas as pd
arrays = [['A', 'A', 'B', 'B'], ['one', 'two', 'one', 'two']]
index = pd.MultiIndex.from_tuples(list(zip(*arrays)), names=['letter', 'number'])
df = pd.DataFrame({'X': [1, 2, 3, 4], 'Y': [5, 6, 7, 8]}, index=index)
df_dropped = df.drop('one', level='number')
print(df_dropped)
This drops every row where the number level equals ‘one’, regardless of which letter group it sits under, leaving only the ‘two’ rows for both A and B. Without the level argument, drop() would look for a label called ‘one’ at the top level and raise a KeyError since no such top-level label exists. If your workflow builds these hierarchical frames by combining several sources first, concatenating DataFrames with pd.concat is the usual step that comes right before this kind of multi-level cleanup.
df.drop() vs del and pop()
Python’s del statement and pandas’ own pop() method can also remove a column, and it helps to know when each one actually fits.
| Method | Returns | Modifies original | Typical use |
|---|---|---|---|
| df.drop(columns=[‘x’]) | New DataFrame | Only with inplace=True | Dropping one or many columns or rows, with error control |
| del df[‘x’] | Nothing | Always | Quick one-off removal in a script, no error handling |
| df.pop(‘x’) | The removed column as a Series | Always | Removing a column while reusing its values elsewhere |
del and pop() only work on a single column at a time and always change the DataFrame directly, which is why the iterative example above needed a loop. df.drop() is the only one of the three built to take a list of labels, respect axis, and skip missing labels gracefully with errors=’ignore’.
Key takeaways
- df.drop(columns=[‘x’]) is the cleanest syntax for dropping columns.
- axis=1 and columns= do the same job, columns= skips the axis argument.
- inplace=True changes the original DataFrame and returns None.
- errors=’ignore’ stops KeyError when a column may not exist.
- level lets drop() target one level of a MultiIndex DataFrame.
- drop() can remove rows too, using index= or axis=0.
- del and pop() only remove one column at a time, always in place.
Frequently asked questions
How do I drop multiple columns in pandas at once?
Pass a list to the columns parameter, like df.drop(columns=['size', 'location']). This removes every column named in the list in a single call.
Does df.drop() change the original DataFrame?
No, not by default. df.drop() returns a new DataFrame unless you set inplace=True, in which case the original DataFrame is changed directly and the method returns None.
What is the difference between axis=1 and columns= in drop()?
They do the same thing. df.drop(['x'], axis=1) and df.drop(columns=['x']) both remove column x. The columns parameter is shorter and avoids confusing axis numbers.
How do I drop a column without getting a KeyError?
Set errors='ignore' in the drop() call, like df.drop(columns=['x'], errors='ignore'). This skips the column quietly if it is not present in the DataFrame.
Can I drop rows and columns in the same drop() call?
Yes. Pass both index and columns in one call, such as df.drop(index=[0], columns=['size']), and pandas removes the specified row and column together.
What is the difference between drop() and del?
drop() can remove multiple labels at once, respects axis and can skip missing labels with errors=’ignore’. del only removes a single column and always changes the DataFrame directly.
How do I permanently remove a column with drop()?
Set inplace=True, for example df.drop(columns=['size'], inplace=True). This changes the DataFrame in place instead of returning a separate copy.
Conclusion
df.drop() covers far more than the five column-dropping patterns it started this guide with. Once you know the parameter table, dropping rows, catching missing labels and cleaning up MultiIndex frames all use the same method.




