search
Search
Unlock 100+ guides
search toc
close
Cancel
Post
account_circle
Profile
exit_to_app
Sign out
What does this mean?
Why is this true?
Give me some examples!
search
keyboard_voice
close
Searching Tips
Search for a recipe:
"Creating a table in MySQL"
Search for an API documentation: "@append"
Search for code: "!dataframe"
Apply a tag filter: "#python"
Useful Shortcuts
/ to open search panel
Esc to close search panel
to navigate between search results
d to clear all current filters
Enter to expand content preview
Doc Search
Code Search Beta
SORRY NOTHING FOUND!
mic
Start speaking...
Voice search is only supported in Safari and Chrome.
Shrink
Navigate to

# Removing multiple columns in Pandas DataFrame

schedule Aug 12, 2023
Last updated
local_offer
PythonPandas
Tags
expand_more
mode_heat
Master the mathematics behind data science with 100+ top-tier guides
Start your free 7-days trial now!

Consider the following DataFrame:

``` df = pd.DataFrame({"A":[3,4],"B":[6,7],"C":[8,9]}, index=["a","b"])df A B Ca 3 6 8b 4 7 9 ```

# Removing multiple columns by integer index

To remove columns at integer indexes `0` and `2`:

``` df = df.drop(columns=df.columns[[0,2]])df Ba 6b 7 ```

## Explanation

The `drop(~)` method only removes columns by their label and so we first need to fetch the column labels:

``` df.columns[[0,2]] Index(['A', 'C'], dtype='object') ```
NOTE

By default, `drop(~)` returns a new DataFrame keeps the original `df` intact. To directly modify `df`, set `inplace=True`.

# Removing multiple columns by label

To remove columns `A` and `B`, pass in a list of column labels like so:

``` df.drop(columns=["A","B"]) Ca 8b 9 ```
Edited by 0 others
thumb_up
thumb_down
Comment
Citation
Ask a question or leave a feedback...
thumb_up
0
thumb_down
0
chat_bubble_outline
0
settings
Enjoy our search
Hit / to insta-search docs and recipes!