'How to repeat the values of first column in multi-level index pivot tables
I'm wondering if there is a method to repeat the value in the first layer of multi-index pivot table.
I have a code like below:
AVG = pd.pivot_table(data=df,
index=['A', 'B'],
values=['C', 'D', 'E'],
aggfunc='mean')
the result is showing like below
A B C D E
ONE 1
2
3
TWO 1
2
3
Is that possible to change the pivot_table code so that values in column A can be repeated as below:
A B C D E
ONE 1
ONE 2
ONE 3
TWO 1
TWO 2
TWO 3
Thank you!!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
