user2293224
user2293224

Reputation: 2220

Nan does not drop out in Python

I have a dataframe which is shown below: enter image description here

I want to drop out all the record that has nan in 'Rego' column. I tried few commands such as

temp_df = temp_df[temp_df['Rego'].notnull()]
temp_df = temp_df[temp_df['Rego'].notna()]
t = temp_df.loc[temp_df['Rego'].notnull()]
temp_df.dropna(axis=0,how='all')
temp_df.dropna(how ='any',inplace=True)

but none of the above commands drop nan values from the Rego column. I looked into existing threads of the forum (Can't drop NAN with dropna in pandas) but couldn't fix the issue. Could anyone guide me where am I making the mistake?

Upvotes: 2

Views: 395

Answers (2)

ansev
ansev

Reputation: 30920

Maybe some nan value is a str, so do this first:

temp_df['Rego'].replace('nan',np.nan,inplace=True)

Then now you can do:

temp_df_fitered=temp_df[temp_df['Rego'].notnull()]

Upvotes: 2

razimbres
razimbres

Reputation: 5015

You didn't assign the result to a dataframe. This may work:

temp_df=temp_df.dropna(axis=0,how='all')

Upvotes: 0

Related Questions