Reputation: 39
I am fairly new to python and pandas so sorry for the beginners question but, I have not yet found a solution to do this simple task.
Dataframe:
Org Data1 Data2
1 1234 Win
1 2345 Win
2 Loss
3 3456 Win
3 4567 Win
I've been trying to use this groupby and apply lambda
df.groupby(["Org"])["Data1", "Data2"].apply(lambda x: ';;'.join(x.astype(str)))
Which does not function properly since the outcome is only
Org
1 Data1;;Data2
2 Data1;;Data2
3 Data1;;Data2
This is what I would like to achieve:
Org Data1 Data2
1 1234 ;; 2345 Win ;; Win
2 NaN Loss
3 3456 ;; 4567 Win ;; Win
The Org represents the defined index which I want to use to group it by. The same Org answers "1 2 3" to Data1 and Data2 should go to the same cell in excel, which I then want to print out as a completely new excel file.
Can anyone help me with this fairly simple (but somehow difficult for me) issue?
Upvotes: 1
Views: 2570