简体   繁体   中英

Pandas pivot_table rearangging rows to columns

I am a Pandas newbie and I like it a lot. I am trying to create a pivot table and having trouble. This is a small image file explaining my problem:

在此处输入图片说明

I have tried the following line but it doesn't output the way I want.

df = df.pivot_table(index = 'Time', columns = 'Item', values = 'Value', aggfunc = list)

try this:

output = pd.pivot_table(df, values='Value', index=['Time', 'ID'],
 columns=['Item'], aggfunc=np.sum, fill_value="")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM