0

I have a csv file with 2 columns and I want to create another csv file and fill it like shown in the figure.

I tried:

xx = pd.read_csv('abc.csv', sep=';', encoding='latin-1')
for row in xx:
    ss = []
    for p in row['id']:
        ss.append(row['description'])

but I don't see how to continue.

dedObed
  • 1,313
  • 1
  • 11
  • 19
This
  • 143
  • 1
  • 2
  • 8
  • use `df.description=df.description.str.split(',')` and then this : https://stackoverflow.com/questions/53218931/how-do-i-unnest-explode-a-column-in-a-pandas-dataframe/53218939#53218939 – anky Mar 25 '19 at 17:59

1 Answers1

0

Try this:

df.groupby('id').agg(",".join).reset_index()

hacker315
  • 1,996
  • 2
  • 13
  • 23
  • Welcome to Stack Overflow. While this command may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. [How to Answer](https://stackoverflow.com/help/how-to-answer) – Popo Mar 25 '19 at 22:01