Closed
Description
Hello there,
Consider this
df = pd.DataFrame({'group' : ['A', 'A', 'A', 'B',
'B', 'B', 'B', 'B'],
'B' : [np.nan,np.nan,np.nan,-4,-2,5,8,7],
'C' : [-5,5,-20,0,np.nan,5,4,-4]})
df
Out[13]:
B C group
0 NaN -5.0 A
1 NaN 5.0 A
2 NaN -20.0 A
3 -4.0 0.0 B
4 -2.0 NaN B
5 5.0 5.0 B
6 8.0 4.0 B
7 7.0 -4.0 B
Now I want to fill forward the missing values in C
for each group
df.groupby('group').C.fillna(method ='ffill')
Out[11]:
0 -5.0
1 5.0
2 -20.0
3 0.0
4 0.0
5 5.0
6 4.0
7 -4.0
Name: C, dtype: float64
df.groupby('group').C.transform('ffill')
Out[12]:
0 -5.0
1 -5.0
2 -5.0
3 5.0
4 5.0
5 5.0
6 5.0
7 5.0
dtype: float64
the transform output is wrong.
Is that expected? Pandas 18.1