Nikki
Nikki

Reputation: 1

How to delete specific values from a column in a dataset (Python)?

I have a data set as below:

enter image description here

I want to remove 'Undecided' from my ['Grad Intention'] column. For this, I created a copy DataFrame and using the code as follows:

df_copy=df_copy.drop([df_copy['Grad Intention'] =='Undecided'], axis=1)

However, this is giving me an error.

How can I remove the row with 'Undecided'? Also, what's wrong with my code?

Upvotes: 0

Views: 7204

Answers (1)

PRIN
PRIN

Reputation: 344

you could simply use:

df = df[df['Grad Intention'] != 'Undecided']
or
df.drop(df[df['Grad Intention'] == 'Undecided'].index, inplace = True)

Upvotes: 1

Related Questions