I have a df that looks like this and I want to have only 1 unique datetime index per row. There are 5 unique cat_idx
values and 3 unique dt_idx
values. The new df will need to have 15 columns. (5 unique cat_idx
* 3 unique dt_idx
)
cat_idx dt_idx val
per_idx
2002-01-01 APERMITE TOTAL 1665.0
2002-01-01 APERMITE SINGLE 1285.0
2002-01-01 APERMITE MULTI 311.0
2002-01-01 AUTHNOTSTD TOTAL 139.0
2002-01-01 AUTHNOTSTD SINGLE 89.0
2002-01-01 AUTHNOTSTD MULTI 46.0
2002-01-01 ASTARTS TOTAL 1698.0
2002-01-01 ASTARTS SINGLE 1318.0
2002-01-01 ASTARTS MULTI 311.0
2002-01-01 UNDERCONST TOTAL 996.0
2002-01-01 UNDERCONST SINGLE 669.0
2002-01-01 UNDERCONST MULTI 297.0
2002-01-01 ACOMPLETIONS TOTAL 1632.0
2002-01-01 ACOMPLETIONS SINGLE 1324.0
2002-01-01 ACOMPLETIONS MULTI 273.0
2002-02-01 APERMITE TOTAL 1787.0
2002-02-01 APERMITE SINGLE 1401.0
My desired output df would have 1 unique datetime per row.
APERMITE_SINGLE APERMITE_MULTI APERMITE_TOT AUTHNOTSTD_SINGLE AUTHNOTSTD_MULTI AUTHNOTSTD_TOT ASTARTS_SINGLE ASTARTS_MULTI ASTARTS_TOT UNDERCONST_SINGLE UNDERCONST_MULTI UNDERCONST_TOT ACOMPLETIONS_SINGLE ACOMPLETIONS_MULTI ACOMPLETIONS_TOT
per_idx
2002-01-01 1285.0 311.0 1665.0 89.0 46.0 139.0 1318.0 311.0 1698.0 669.0 297.0 996.0 1324.0 297.0 1632.0
This sample of data has only one datetime stamp, I will need to iterate through the datetime indexes and make similar rows per datetime. I'm not sure how to go about this but after searching for similar questions this one and this question had similar values or names whereas I need new columns to be created.
Also, if the title can be improved please let me know as I'm not entirely sure how to phrase this question.