When I import my data file with Pandas I get following data frame:
product feature_1 feature_2
0 a 11 12
1 NaN 13 14
2 NaN 15 16
3 NaN 17 18
4 NaN 19 20
5 b 21 22
6 NaN 23 24
7 NaN 25 26
8 c 27 28
9 NaN 29 30
10 NaN 31 32
What I need to do is to substitute the NaNs with the next non-NaN element above them so I get following data frame:
product feature_1 feature_2
0 a 11 12
1 a 13 14
2 a 15 16
3 a 17 18
4 a 19 20
5 b 21 22
6 b 23 24
7 b 25 26
8 c 27 28
9 c 29 30
10 c 31 32
What I did (see gist for code and datafile):
- Import my data into a list of dicts
- iterate through the list and make the modifications
- import the list into a data frame
How can I make this happen directly in Pandas without doing the list preprocessing beforehand ?