0

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?

2
  • df = df[df['Grad Intention'] != 'Undecided'] Commented Oct 3, 2021 at 10:52
  • thanks this worked. But if i try to pass this data frame to construct a cross tab it shows error Code- pd.crosstab(df.copy['Gender'], df.copy['Grad Intention']) Error- TypeError: 'method' object is not subscriptable Can you let me know what is going wrong here? Commented Oct 5, 2021 at 7:02

1 Answer 1

1

you could simply use:

df = df[df['Grad Intention'] != 'Undecided'] or df.drop(df[df['Grad Intention'] == 'Undecided'].index, inplace = True) 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks this worked. But if i try to pass this data frame to construct a cross tab it shows error Code- pd.crosstab(df.copy['Gender'], df.copy['Grad Intention']) Error- TypeError: 'method' object is not subscriptable Can you let me know what is going wrong here?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.