This is my dataframe, I have a multiindex on time and ID.
+------+-------+----------+-----------+
| col1 | col2 | col3 | col4 |
+-------+------+------+-------+----------+-----------+
| ID | t | | | | |
+-------+------+------+-------+----------+-----------+
| id1 | t1 | 10 | nan | nan | 1 |
| id1 | t2 | 10 | 110 | 1 | nan |
| id1 | t3 | 12 | nan | nan | nan |
| id2 | t1 | 12 | 109 | 15 | 1 |
| id2 | t4 | 12 | 109 | nan | 1 |
| id2 | t7 | 20 | nan | nan | nan |
+-------+------+------+-------+----------+-----------+
Is it possible to do a multi-index fwd fill only on col3 and col4?
+------+-------+----------+-----------+
| col1 | col2 | col3 | col4 |
+-------+------+------+-------+----------+-----------+
| ID | t | | | | |
+-------+------+------+-------+----------+-----------+
| id1 | t1 | 10 | nan | nan | 1 |
| id1 | t2 | 10 | 110 | 1 | 1 |
| id1 | t3 | 12 | nan | 1 | 1 |
| id2 | t1 | 12 | 109 | 15 | 1 |
| id2 | t4 | 12 | 109 | 15 | 1 |
| id2 | t7 | 20 | nan | 15 | 1 |
+-------+------+------+-------+----------+-----------+
What I've tried so far:
df[['col3','col4']].ffill() #how to account for the multiindex?
df[['col3','col4']].fillna(df.groupby(['ID','t'])[['col3', 'col4']].ffill()) #did not work
df.reindex(['ID','t'], method='ffill') #this is probably incomplete, and I got 'expected Tuple, got str'