For the following dataframe:
every group of c
should have three values of b
. The second value of a
should be the average of the first and third value of a
.
What is the easiest way to insert the "missing" row with a=48
, b=42
, c=4
between index = 0
and index = 1
?
df_x = pd.DataFrame({"a": [47, 49, 55, 54, 53, 24, 27, 30], "b": [41, 43, 51, 52, 53, 41, 42, 43], "c": [4, 4, 5, 5, 5, 4, 4, 4]})
df_x
Out[14]:
a b c
0 47 41 4
1 49 43 4
2 55 51 5
3 54 52 5
4 53 53 5
5 24 41 4
6 27 42 4
7 30 43 4
If I use groupby('c').transform(my_func)
or groupby('c').apply(my_func)
, I face the situation that the first call to my function my_func
is done twice.