答案 0 :(得分:1)
您需要reindex
乘以unique
列的值sort_values
,需要Load an html5 canvas into a PIL Image with Django乘列Loc_Time
,因为Time
默认排序:>
pivot
详细信息:
df1 = df.pivot('Group','Loc_Time','Value')
df1 = df1.reindex(columns=df.sort_values('Time')['Loc_Time'].unique())
print (df1)
Loc_Time loc1_Week1 loc2_Week1 loc3_Week1 loc1_Week2 loc2_Week2 \
Group
prod1 10 12 14 11 13
prod2 20 22 24 21 23
Loc_Time loc3_Week2
Group
prod1 15
prod2 25