1

I'm trying to replace certain columns of my dataframe that contains NaN with 0's. For example, I have a column named 'CQ Exp Net Rep Liquid' that has some values in the column that are NaN.

I've tried running

df[['CQ Exp Net Rep Liquid']].fillna(0,inplace=True)

and then when I proceed to run

df[['CQ Exp Net Rep Liquid']].sample(n=10)

I am returning the column with NaNs still. I have tried df.bfill as well to no avail. Does anyone know what is going on?

eshirvana
  • 23,227
  • 3
  • 22
  • 38
ntwong
  • 89
  • 5
  • 6
    check if `'NaN'` is not just a string – RomanPerekhrest Jan 13 '23 at 19:30
  • 4
    What is the output of `df.isna().sum()` on the original DataFrame? – mozway Jan 13 '23 at 19:34
  • 5
    that df[[...]] thing might or might not be a view. better avoid inplace=True and assign back. also you don't need two brackets: `df["name"] = df["name"].fillna(0)`. Two of them results in a frame, one gives a Series (in nonmultiindex frames). – Mustafa Aydın Jan 13 '23 at 19:36
  • 3
    Please make a [mre]. For specifics, see [How to make good reproducible pandas examples](/q/20109391/4518341). – wjandrea Jan 13 '23 at 19:40

0 Answers0