Python Forum

Full Version: string agg separated by comma
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
dfg = pd.DataFrame({"A": [1, 1, 2, 3, 3, 4],
"B": ['AA', 'AA', 'AB', 'CD', 'CD', 'EF'],
"C": ['A1', 'B1', 'C1', 'D1', 'E1', 'F1']})
print(dfg.groupby(["A","B"], as_index=False).sum())
Output is as below
A B C
0 1 AA A1B1
1 2 AB C1
2 3 CD D1E1
3 4 EF F1

I want output will be as below. Column C will be aggregated and separated by comma.
A B C
0 1 AA A1,B1
1 2 AB C1
2 3 CD D1,E1
3 4 EF F1
So show your effort so far (code).