Suposse we have this df:
| id | dates | |
|---|---|---|
| 0 | 12 | 2012-12-06 |
| 1 | 12 | 2012-12-07 |
| 2 | 13 | 2012-01-02 |
| 3 | 13 | 2012-01-03 |
| 4 | 14 | 2012-12-06 |
How could I merge the rows based on the unique id values and store all other variables with ,together (let’s say date or even more columns), for example:
| id | all dates | |
|---|---|---|
| 0 | 12 | 2012-12-06 , 2012-12-07 |
| 1 | 13 | 2012-01-02 , 2012-01-03 |
| 2 | 14 | 2012-12-06 |
>Solution :
Based on this you can adjust for extra columns as you’d like.
df_new['date2']=df_new.groupby('name').shift(-1)
df_new['date2']=';'+df_new['date2']
df_new['date2']=df_new['date2'].fillna('')
df_new['date3']=df_new['date']+df_new['date2']