问题
Having problems with the .dropna() method. I have created a new variable energy_c which is a copy of energy but with mont being more or equal to 0.1.
I then took out the columns with nothing in after printing them and then am trying to drop all rows that have NaN values in the remaining columns. However my output is returning NaN values even after using .dropna().
energy_c = energy.loc[energy.loc[:, 'mont'] >= 0.1].copy()
energy_c.columns[energy.isna().all()].tolist()
drop_cols = energy_c.loc[:,['EndDate', 'Ref', 'dis']]
energy_c.drop(drop_cols, axis=1, inplace=True)
energy_c.dropna()
print(energy_c)
Could someone advise as to what I have done wrong?
Thanks.
回答1:
dropna is not an inplace method, try energy_c = energy_c.dropna().
回答2:
Try
energy_c.dropna(inplace = True)
This does the operation inplace and returns None, according to the documentation.
来源:https://stackoverflow.com/questions/53322643/problem-dropna-method-is-returning-nan-values