Pivot this table in pandas

Question:

I have this data here, image follows:

This data

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.

Asked By: LUCAS XX

||

Answers:

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()
Answered By: mozway
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.