Combine multiple rows to a single line in pandas data frame

Advertisements

I have a dataframe in pandas that gives you the below table:
enter image description here

I would like to get the below results by summing up the calls and getting the type in one single line. (you can observe the yellow rows)

>Solution :

Try:

# aggregate by Key
# keep the first No, join types, and sum calls
df.groupby("Key", as_index=False).agg({"No": "first", "Type": "; ".join, "Calls": "sum"})

Leave a ReplyCancel reply