How to change dataframe like this
date | item_code | qty |
---|---|---|
2023-01-01 | HTA-01 | 16 |
2023-01-01 | HTA-02 | 29 |
2023-01-01 | HTB-07 | 1 |
2023-01-02 | HTA-01 | 18 |
2023-01-02 | HTA-02 | 34 |
to this in python
date | HTA-01 | HTA-02 | HTB-07 |
---|---|---|---|
2023-01-01 | 16 | 29 | 1 |
2023-01-02 | 18 | 34 | nan |
Each unique value from item_code become column. The value from its is from qty column. This is sample data to try
data = { 'date': ['2023-01-01','2023-01-01','2023-01-01','2023-01-02', '2023-01-02'],
'item_code':['HTA-01', 'HTA-02', 'HTB-07', 'HTA-01', 'HTA-02'],
'qty':['16', '29', '1', '18', '34'],
}
df = pd.DataFrame(data2)