Hi Raul, thank you very much for your support!
For your questions, are you performing it in Microsoft Excel, if yes, you may try to record Macro when you do pivot, and refer to the steps to write the Python script.
Else, may need your help to share more information.
Best regards,
Kah Em