Reputation: 2220
I have a dataframe which is shown below:
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
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
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