newbe here. I have cleaned and sorted my dataset:
Staff | SomeData | Date |
---|---|---|
Alex | Data1 | 05 Jun 2023 |
Alex | Data2 | 05 Jun 2023 |
Alex | Data3 | 05 Jun 2023 |
John | Data4 | 05 Jun 2023 |
John | Data5 | 05 Jun 2023 |
Fred | Data6 | 05 Jun 2023 |
Fred | Data7 | 05 Jun 2023 |
Alex | Data8 | 06 Jun 2023 |
Alex | Data9 | 06 Jun 2023 |
Alex | Data10 | 06 Jun 2023 |
John | Data11 | 06 Jun 2023 |
John | Data12 | 06 Jun 2023 |
Fred | Data13 | 07 Jun 2023 |
Fred | Data14 | 07 Jun 2023 |
need to turn it to following
Staff | 05 Jun 2023 | 06 Jun 2023 | 07 Jun 2023 |
---|---|---|---|
Alex | Data1 | Data8 | No Data |
Alex | Data2 | Data9 | No Data |
Alex | Data3 | Data10 | No Data |
John | Data4 | Data11 | No Data |
John | Data5 | Data12 | No Data |
Fred | Data6 | No Data | Data13 |
Fred | Data7 | No Data | Data14 |
I have created new empty dataframe with needed columns:
uniqueDates=df['Date'].unique()
NewDF["Staff"]=''
for column in uniqueDates:
NewDF[column]=''
Tried to use nested For loops with If/Else, loc/iloc/ isin() etc. I can't figure out how to get desired result. Found one of the posts here suggesting to use Pivot, couldn't figure out how to tweak it to my needs Would you please point me in the right direction? Any useful panda methods? Regards