geds133
geds133

Reputation: 1485

Problem: dropna() method is returning NaN values

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.

Upvotes: 1

Views: 153

Answers (2)

Lenka Vraná
Lenka Vraná

Reputation: 1706

Try

energy_c.dropna(inplace = True)

This does the operation inplace and returns None, according to the documentation.

Upvotes: 2

vlizana
vlizana

Reputation: 3252

dropna is not an inplace method, try energy_c = energy_c.dropna().

Upvotes: 1

Related Questions