I have a df
like this (its just an example):
date(YYYY-mm-dd) money money_diff acc
2019-02-01 110 diff_1 236234623-1
2019-03-01 244 diff_2 236234623-1
2019-04-01 402 diff_3 236234623-1
2019-02-01 429 diff_4 876567856-k
2019-03-01 424 diff_5 876567856-k
2019-04-01 125 diff_6 876567856-k
2019-08-01 346 diff_7 876567856-k
... ... ...
2020-01-01 348 diff_20 456745675-5
2020-02-01 745 diff_21 456745675-5
2020-03-01 457 diff_22 456745675-5
2020-04-01 567 diff_23 023603460-0
2020-05-01 774 diff_24 023603460-0
... ... ... ...
2023-01-01 245 diff_43 634034060-3
2023-02-01 458 diff_44 634034060-3
2023-03-01 457 diff_45 634034060-3
What I want is for the acc
column to be the first column (with unique str values), the values of the date
column to be my other headers, and the values inside to be those of money_diff
column. What I want is to have a tabular structure like this (I can drop
money
column, I will not use it):
acc 2019-02-01 2019-03-01 2019-04-01 ... 2023-03-01
236234623-1 diff_1 diff_2 diff_3 ... diff_X1
876567856-k diff_4 diff_5 diff_6 ... diff_X2
456745675-5 diff_X3 diff_X4 diff_X5 ... diff_X6
023603460-0 diff_X6 diff_X7 diff_X8 ... diff_X9
634034060-3 diff_X10 diff_X11 diff_X12 ... diff_45
I know that the requirement for this is that acc
column have the same dates, and yes, they do.
I tried to use pd.melt
function but I didn't have my results:
pd.melt(df, id_values='acc', var_values='money_diff','date')