pandas df after fillna() is still NaN -


a 40000 rows 1 column data saved excel. there hundred null values in it. such row 361... when carried out df.fillna(method='bfill'), nan values still nan. if sliced df fragment contained null values, processed expectently. tried still not fill nan cells. what's wrong it? df file here:

excel file click here

df=pd.read_execel('npp.xlsx') df.fillna(method='bfill') print( df.iloc[360:370,] ) out[122]:            0 t360     nan t361     nan t362     nan t363     nan t364  220.50 t365  228.59 t366     nan t367     nan t368     nan t369     nan 

when apply fillna() on sliced df, nan values replaced:

print( df.iloc[360:370,].fillna(method='bfill') )        0 t360  220.50 t361  220.50 t362  220.50 t363  220.50 t364  220.50 t365  228.59 t366     nan t367     nan t368     nan t369     nan 

you need assign output:

df = pd.read_excel('npp.xlsx') df = df.fillna(method='bfill')  df = df[df[0].isnull()] print (df) empty dataframe columns: [0] index: [] 

or use inplace=true parameter:

df = pd.read_excel('npp.xlsx') df.fillna(method='bfill', inplace=true) df = df[df[0].isnull()] print (df) empty dataframe columns: [0] index: [] 

or shorter:

df = df.bfill() 

df.bfill(inplace=true) 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -