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?