Home > Mobile >  how to drop nan values from pandas dataframe
how to drop nan values from pandas dataframe

Time:07-16

Sample data:

      WN    TOW    Azimuth  Elevation   S4_SIG1 S4_SIG2 TEC
0   2138    432060  289           38    0.087   0.075   16.083
1   2138    432060  37             5    0.175   nan     22.237
2   2138    432060  42            39    0.058   nan     11.188
3   2138    432060  283            6    0.210   nan     19.156
4   2138    432060  23            60    0.054   nan     14.448

I am using

df4=df3.dropna(how='any')
df4

But then it is returning same dataframe. I tried subset=['S4_SIG2']still it didnt worked out.SOS!!

CodePudding user response:

#change to type float
df3 ['WN'] = df3['WN'].astype(float)
df3 ['TOW'] = df3['TOW'].astype(float)
df3 ['Azimuth'] = df3['Azimuth'].astype(float)
df3 ['Elevation'] = df3['Elevation'].astype(float)
df3 ['S4_SIG1'] = df3['S4_SIG1'].astype(float)
df3 ['S4_SIG2'] = df3['S4_SIG2'].astype(float)
df3 ['TEC'] = df3['TEC'].astype(float)
df3.dropna()

CodePudding user response:

You can fix a DataFrame that should be numeric, but that's currently object typed by doing:

for col in df:
    df[col] = pd.to_numeric(df[col])

CodePudding user response:

You are missing the inplace= True

df3.dropna(how='any',inplace= True)

df3

  • Related