Python Forum
string agg separated by comma
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
string agg separated by comma
#1
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
Reply
#2
So show your effort so far (code).
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How can histogram bins be separated and reduce number of labels printed on x-axis? cadena 1 882 Sep-07-2022, 09:47 AM
Last Post: Larz60+
  [SOLVED] [BeautifulSoup] Turn select() into comma-separated string? Winfried 0 1,112 Aug-19-2022, 08:07 PM
Last Post: Winfried
  How to format Excel column with comma? dee 0 1,360 Jun-13-2022, 10:11 PM
Last Post: dee
  decimal comma DPaul 9 2,268 Feb-22-2022, 12:25 PM
Last Post: DeaD_EyE
  Adding a comma in the resulting value stsxbel 6 2,637 May-22-2021, 09:24 PM
Last Post: stsxbel
  How to instantly add quotation marks and comma for parameters? cheers100 4 8,049 Oct-22-2020, 12:51 PM
Last Post: cheers100
  print scripts example includes comma that seems to serve no purpose flour_power_33 5 2,795 Sep-02-2020, 03:32 AM
Last Post: flour_power_33
  How to print string multiple times separated by delimiter Mekala 1 1,892 May-23-2020, 09:21 AM
Last Post: Yoriz
  Grabbing comma separed values from SQLite and putting them in a list PythonNPC 8 4,007 Apr-10-2020, 02:39 PM
Last Post: buran
  Phyton code to load a comma separated csv file in to a dict and then in to a dB mrsenorchuck 2 2,658 Nov-29-2019, 10:59 AM
Last Post: mrsenorchuck

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020