1

i got this pivot table result

result i got

my pivot table code looks like this:

result = pd.pivot_table(excel, values=["Percent"], columns='Date', index='items', aggfunc={"Percent":np.mean})

but i need to looks like this:

result i want

Anyone knows how i can get it?

i tried:

result.reset_index(level=0, drop=True)

but drops the wrong column

Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52
MarcelGlez
  • 11
  • 2

1 Answers1

0

You don't need to specify aggfunc with a dict as you have only one column of value:

result = excel.pivot_table(index='items', columns='Date',
                           values='Percent', aggfunc='mean')
Corralien
  • 109,409
  • 8
  • 28
  • 52