1

i am using apply(",".join) to concatenate,

ICPMMRM Charge_Code
0000000646DE9C5 SHSD15
0000000646DE9C5 6
0000000646DE9C5 10
network_report_A=network_ctct.groupby('ICPMMRM')['Charge_Code'].apply(str).apply(",".join)
network_report_A.head()
ICPMMRM
0000000646DE9C5    0, , , , ,S,H,S,D,1,5,\n,1, , , , , , , , , ,6...
0000000650DE2E7    3, , , , ,S,H,S,D,1,5,\n,4, , , , , , , , , ,6...
0000002229DE6AA    6, , , , ,S,H,S,D,1,5,\n,7, , , , , , , , ,1,7...
0000002464DED52    8, , , , , ,S,H,1,-,L,1,-,C,K,V,A,\n,9, , , , ...
0000003723CEE85    1,6, , , , ,C,C,2,-,L,2,-,C,K,V,A,\n,1,7, , , ...
Name: Charge_Code, dtype: object

but i expect the result like SHSD15,6,10

wjandrea
  • 28,235
  • 9
  • 60
  • 81

1 Answers1

1

The ",".join may be called on the values of all the column, not on each (what apply does). Also you don't need any groupby just join the values of the column

import pandas as pd

network_ctct = pd.DataFrame([["0000000646DE9C5", "SHSD15"],
                             ["0000000646DE9C5", "6"],
                             ["0000000646DE9C5", "10"]],
                            columns=["ICPMMRM", "Charge_Code"])

network_report_A = ",".join(network_ctct['Charge_Code'].apply(str))
print(network_report_A)  # SHSD15,6,10
azro
  • 53,056
  • 7
  • 34
  • 70