There is no way to find this question anywhere, so just try here:
What I'm trying to do is basically modify an existing DataFrame using group functionality and a self-written function:
benchmark =
x y z field_1
1 1 3 a
1 2 5 b
9 2 4 a
1 2 5 c
4 6 1 c
What I want to do is groupby field_1, apply the function using certain columns as input, in this case the columns xand y, and then add the result to the original DataFrame benchmarkas a new column called new_field. The function itself depends on the value of field_1, i.e. field_1=awill give a different result compared to field_1=betc. (Consequently, the grouping will begin with).
The pseudocode will look something like this:
1. grouped_data = benchmark.groupby(['field_1'])
2. apply own_function to grouped_data; with inputs ('x', 'y', grouped_data)
3. add back result from function to benchmark as column 'new_field'
Thank,
:
benchmark =
x y z field_1
1 1 3 a
1 2 5 b
9 2 4 a
1 2 5 c
4 6 1 c
:
DataFrame separate_data, x,
separate_data =
x a b c
1 1 3 7
2 2 5 6
3 2 4 4
4 2 5 9
5 6 1 10
benchmark DataFrame. separate_data, , field_1 benchmark (.. (a,b,c) ). x- benchmark.
:
benchmark =
x y z field_1 field_new
1 1 3 a interpolate using separate_data with x=1 and col=a
1 2 5 b interpolate using separate_data with x=1 and col=b
9 2 4 a ... etc
1 2 5 c ...
4 6 1 c ...
?