1

I have a small block to list the content of Y compared X

input df

X    Y
1    a
1    a
2    a
2    a
3    a
4    a
4    b
4    b
2    c
3    c
3    c
5    a

Output desired

Y           X
a     [1,1,2,2,3,4,5]
b     [4,4]
c     [2,3,5]

I tried this

for idx, row in df.iterrows():
    list = row['Y']
    Id = []
    Id=row['X']
data_df = pd.DataFrame(list(Id), columns=['Y', 'X'])
data_df

but no results

Thanks

MoMo
  • 107
  • 5

0 Answers0