I have this data here, image follows:
I need to pivot the table, the expected output is:
Description From To 2021-11-01
A A X VALUE COLUMN
B B P VALUE COLUMN
C D T VALUE COLUMN
I already tried
final_data.pivot_table(index=[['Description', 'From', 'To']], columns='Date', values=['Value'], aggfunc=len).reset_index()
And retrieve the error:
Grouper and axis must be same length
I don't need agg function.
Thanks in advance.
CodePudding user response:
The issue likely comes from the nested list used as value of the index
parameter.
Use a simple list:
final_data.pivot_table(index=['Description', 'From', 'To'], columns='Date', values='Value', aggfunc=len).reset_index()