0

enter image description here

Suppose that I have a dataframe(df) like above, I want to run df.groupby(['id', 'client']) and the apply union on the items column ? The result should be one row -> id = 1 and client = 70 items= {1,2,3,4,5,6,7}.

I appreciate any help with this!

Dani
  • 857
  • 1
  • 6
  • 8
  • 1
    Does this answer your question? [Set Union in pandas](https://stackoverflow.com/questions/38428108/set-union-in-pandas). Or perhaps this: [Row-wise unions in pandas groupby](https://stackoverflow.com/questions/25020595/row-wise-unions-in-pandas-groupby). `df.groupby(['id', 'client']).agg(lambda x: functools.reduce(set.union, x))` – mcskinner Apr 17 '20 at 23:56
  • thank you @mcskinner, your suggestion is working! – Dani Apr 18 '20 at 00:04

0 Answers0