1

i have a dataframe of 400 x 25. i am supposed to remove ALL Nans from the dataset and then select only 3 columns to work on from the 25 columns. I have done this using:

df1.dropna(axis=0)
df2=df1.loc[:,['bgr','wc','rc']]
df2['rc']=pd.to_numeric(df['rc'],errors='coerce')
df2['wc']=pd.to_numeric(df['wc'],errors='coerce')

rc and wc were showing up as objects when i did the dtypes, so i converted them to floats.

now, after i drop the Nans, i am left with only 252 rows. so i assumed that all the Nans had gone.

but when i did a df2.describe(), it showed 251 as count for 'rc' but 252 for 'bgr' and 'wc'. this was odd, so when i did a df2.rc.unique(), it showed up a Nan!!!!

my question: how do i remove this Nan??

Mansoor Iqbal
  • 27
  • 1
  • 5
  • 1
    Possible duplicate of [Can't drop NAN with dropna in pandas](http://stackoverflow.com/questions/33643843/cant-drop-nan-with-dropna-in-pandas) – Vivek Kumar Apr 11 '17 at 09:25

1 Answers1

4

assign back:

df = df.dropna(axis=0)

by default it's not inplace unless you say so:

df.dropna(axis=0, inplace=True)

Check the docs

EdChum
  • 376,765
  • 198
  • 813
  • 562