I want to fill empty cells in Visit and X1 for each Subject with Previous value and return a dataframe.
Subject Visit X1 X2
A aaa 164 16
A creamy 167 168
A
B yyy 173 176
B ice cream 1760 178
B 1788
B ccc 17 17
C cream 1788 1789
C doo 1789 179
output would be like :
Subject Visit X1 X2
A aaa 164 16
A creamy 167 168
A creamy 167
B yyy 173 176
B ice cream 1760 178
B ice cream 1760 1788
B ccc 17 17
C cream 1788 1789
C doo 1789 179
I tried :
df.fillna(method='ffill')
but it is not working and doesn't return the dataframe.