第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

整理大熊貓實驗結(jié)果

整理大熊貓實驗結(jié)果

蝴蝶刀刀 2021-11-02 13:54:53
我有以下輸入數(shù)據(jù)。每一行都是一個實驗的結(jié)果:  instance algo  profit  time        x    A      10   0.5        y    A      20   0.1        z    A      13   0.7        x    B      39   0.9        y    B      12   1.2        z    B      14   0.6我想生成下表:            A               B   instance    profit  time    profit  timex           10      0.5     39      0.9y           20      0.1     12      1.2z           13      0.7     14      0.6我曾嘗試使用 pivot 和 pivot_table 但沒有成功。有沒有辦法用熊貓來達到這個結(jié)果?
查看完整描述

2 回答

?
BIG陽

TA貢獻1859條經(jīng)驗 獲得超6個贊

首先melt獲取'profit'和'time'在同一列中,然后使用pivot table具有多個列級別的a


(df.melt(id_vars=['instance', 'algo'])

.pivot_table(index='instance', columns=['algo', 'variable'], values='value'))

#algo          A           B     

#variable profit time profit time

#instance                        

#x          10.0  0.5   39.0  0.9

#y          20.0  0.1   12.0  1.2

#z          13.0  0.7   14.0  0.6


查看完整回答
反對 回復(fù) 2021-11-02
?
富國滬深

TA貢獻1790條經(jīng)驗 獲得超9個贊

set_index和unstack:


df.set_index(['instance', 'algo']).unstack().swaplevels(1, 0, axis=1)



         profit     time     

algo          A   B    A    B

instance                     

x            10  39  0.5  0.9

y            20  12  0.1  1.2

z            13  14  0.7  0.6

(df.set_index(['instance', 'algo'])

   .unstack()

   .swaplevel(1, 0, axis=1)

   .sort_index(axis=1))


algo          A           B     

         profit time profit time

instance                        

x            10  0.5     39  0.9

y            20  0.1     12  1.2

z            13  0.7     14  0.6

另一種選擇是使用pivotand swaplevel:


(df.pivot('instance', 'algo', ['profit', 'time'])

   .swaplevel(1, 0, axis=1)

   .sort_index(axis=1))


algo          A           B     

         profit time profit time

instance                        

x          10.0  0.5   39.0  0.9

y          20.0  0.1   12.0  1.2

z          13.0  0.7   14.0  0.6


查看完整回答
反對 回復(fù) 2021-11-02
  • 2 回答
  • 0 關(guān)注
  • 185 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號