I have a problem that can be visualized in the following way:
| Our | Cat | The | Home | They | Able | |
|---|---|---|---|---|---|---|
| Alice | 10 | 15 | NaN | 30 | 20 | 25 |
| Bob | 12 | NaN | 14 | 29 | NaN | 30 |
| John | NaN | 9 | NaN | NaN | NaN | 20 |
| Tyler | 11 | 12 | 13 | 24 | 25 | 26 |
In general, there is numeric data assigned to each person (index) in each column, but there are empty spaces.
I am wondering how to fill each NaN with the average for the same person for the columns with the same name length as the column with the missing value. In other words, how to combine fillna() and mean() with some custom logic for which columns are taken into consideration. The perfect result would be:
| Our | Cat | The | Home | They | Able | |
|---|---|---|---|---|---|---|
| Alice | 10 | 15 | 12.5 | 30 | 20 | 25 |
| Bob | 12 | 13 | 14 | 29 | 29.5 | 30 |
| John | 9 | 9 | 9 | 20 | 20 | 20 |
| Tyler | 11 | 12 | 13 | 24 | 25 | 26 |
With the numbers in bold being the averages for the same person for the same "column length".
Unfortunately, in my real life scenario there are hundreds of columns, so I cannot manually list the corresponding columns for each of them.
Thanks for all the help in advance.