1
Angesichts der folgenden Tabelle Schwenk:Pandas Sortieren Multiindex Pivot Tabelle
import pandas as pd
import numpy as np
df = pd.DataFrame(
{'YYYYMM':[201603,201503,201403,201303,201603,201503,201403,201303],
'Count':[5,6,2,7,4,7,8,9],
'Group':['A','A','A','A','B','B','B','B']})
df['YYYYMM']=df['YYYYMM'].astype(str).str[:-2].astype(np.int64)
t=df.pivot_table(df,index=['Group'],columns=['YYYYMM'],aggfunc=np.sum)
t
Count
YYYYMM 2013 2014 2015 2016
Group
A 7 2 6 5
B 9 8 7 4
Ich möchte die Reihen (Gruppen A und B) ansteigend bis zum Jahr 2016 auf solche Art, die Gruppe B obigen Gruppe A ist, während die Halte Gesamtanordnung der Pivot-Tabelle.
Vielen Dank im Voraus!