0

Please,

Can you help me about this code?

Say I have a dataframe like this:

   ID    values
0   1        A
1   2        B
2   1        A
3   4        C

I want this DF

  ID    values
    0   1        A,A
    1   2        B
    3   4        C

Or:

  ID    values
    0   1        2xA
    1   2        B
    3   4        C

Thanks.

  • 1
    `df.groupby('ID')['values'].agg(','.join)` – anky Mar 18 '20 at 16:20
  • 1
    No you don't want that. If it is to learn how to build a list of a string inside dataframe cells, it can be acceptable. In any *real* use case it is terrible because you a explicitely building a non vectorizable element. – Serge Ballesta Mar 18 '20 at 16:23
  • Agreed with @SergeBallesta , try not to do that – anky Mar 18 '20 at 16:27

0 Answers0