0

I am working on imputing NaNs of rows based on certain columns. So my dataframe looks something like this:

Product Store Name January Sales February Sales March Sales

For example, January Sales would be NaN for a combination of Product and Store Name and am imputing data based on other months averages. Also, other attributes, February Sales might also have NaNs in the same row.

The code that I used was:

indexes = df.index[df['January Sales'].isna()].to_list()
fillCols = df.iloc[:, 3:]
df.loc[indexes, 'January Sales'].fillna(fillCols.mean(axis=0), inplace=True)

But the above code doesn't seem to be working, the code won't impute data, however, when broken down different pieces do work, how to solve this problem?

axiomatic
  • 39
  • 2
  • Are you trying to replace your nan with the mean for january or for january, february and march? – user14518362 Jun 03 '21 at 23:40
  • 1
    Please include a small subset of your data as a copyable piece of code that can be used for testing as well as your expected output for the provided data. See [MRE - Minimal, Reproducible, Example](https://stackoverflow.com/help/minimal-reproducible-example), and [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – Utsav Jun 04 '21 at 00:21

0 Answers0