It seems like there are similar questions, but I could not find the right answer. Let's say this is my information frame, which has different observations for different brands of cars:
df = pandas.DataFrame({'Car' : ['BMW_1', 'BMW_2', 'BMW_3', 'WW_1','WW_2','Fiat_1', 'Fiat_2'],
'distance' : [10,25,22,24,37,33,49]})
For simplicity, suppose my function multiplies the first element by two and the second by three:
def my_func(x,y):
z = 2x + 3y
return z
I want to get paired combinations of distances covered by cars and use them in my_func. But there are two conditions: x and y cannot be identical brands, and combinations should not be duplicated. The desired output looks something like this:
Car Distance Combinations
0 BMW_1 10 (BMW_1,WW_1),(BMW_1,WW_2),(BMW_1,Fiat_1),(BMW_1,Fiat_1)
1 BMW_2 25 (BMW_2,WW_1),(BMW_2,WW_2),(BMW_2,Fiat_1),(BMW_2,Fiat_1)
2 BMW_3 22 (BMW_3,WW_1),(BMW_3,WW_2),(BMW_3,Fiat_1),(BMW_3,Fiat_1)
3 WW_1 24 (WW_1, Fiat_1),(WW_1, Fiat_2)
4 WW_2 37 (WW_2, Fiat_1),(WW_2, Fiat_2)
5 Fiat_1 33 None
6 Fiat_2 49 None
//Output
[120, 134, 156, 178]
[113, 145, 134, 132]
[114, 123, 145, 182]
[153, 123]
[120, 134]
None
None
Note. I have compiled numbers for output.
The next step. I want to get the maximum numbers from the arrays of the string "output" for each brand. And the final data should look like
Car Max_Distance
0 BMW 178
1 WW 153
2 Fiat None
, -