0

I have the following dataframe:

employee_id company transfer_date
1743        cmp1    2018-04-30
1743        cmp2    2018-10-05
1743        cmp3    2019-10-23
1744        cmp5    2022-11-11

I need to flatten it and display 1 employee per row as below:

employee_id company1 transfer_date1 company2 transfer_date2 company3 transfer_date3
1743        cmp1     2018-01-30     cmp2     2018-10-05     cmp3     2019-10-23
1744        cmp5     2022-11-11     NAN      NAN            NAN      NAN

I've tried using unstack or a pivot table but no luck.

If there was a forth transfer for employee 1743 it should have added a company4 and transfer_date4 column.

Any help will be appreciated.

Kritz
  • 7,099
  • 12
  • 43
  • 73

0 Answers0