How to Select All Columns Except One in Pandas?

Spread the love

Problem –

You want to select all columns except one in pandas.

Solution –

To select all column except the one column in pandas you can use the drop method in pandas.

Let’s read a dataset to illustrate it.

import pandas as pd

url = ''
df = pd.read_csv(url)

Let’s say I want to select all the columns except the Age column. For that I will write.

df_new = df.drop('Age', axis=1)

IF you are not interested to create a new dataframe then you can use drop like this.


Related Posts –

  1. Pandas – Delete one or more columns from a dataframe

Rating: 1 out of 5.

Leave a Reply