*This isn't the first time it is asked here but I haven't seen any Q related to multiple columns
Example data:
1 2 3 ........
Orange |a |d |e
Orange |b |b |e
Black |y |z |nan
Black |x |y |nan
Black |z |nan |nan
Black |w |x |y
Blue |g |h |i
Blue |i |nan |nan
..
I am trying to join same indexed rows, and drop duplicates i.e orange: a b d e
Joining same index rows done by:
df = df.groupby(df.index).agg(lambda z: ','.join(z.astype(str)))
After that I got all rows concatenated with a comma just inlaid in some columns. I tried to move them to separate columns:
df = df.columns.str.split(',',expand=True)
But it did not work.
After I move them to separated columns, I'll use drop_duplicates().
Need help with the expand part.
Edited excpected (order isn't necessary):
1 2 3 4 5 6 7....
Orange |a |b |d |e
Black |y |z |x |w
Blue |g |h |i