1 回答
TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超6個贊
我想你想要:
data['Max'] = data.idxmax(axis=1)
或者如果你想要特定的年份:
data['Max'] = data[[2002,2003,2004,2005]].idxmax(axis=1)
如果你Year是整數(shù),否則:
data['Max'] = data[['2002','2003','2004','2005']].idxmax(axis=1)
而不是使用大字符串進(jìn)行索引'2002, 2003, 2004, 2005'。
輸出:
Year 2002 2003 2004 2005 Max
Month
Apr 645 709 178 800 2005
Aug 217 867 515 748 2003
Dec 179 230 121 905 2005
Feb 756 717 879 772 2004
Jan 615 329 896 108 2004
Jul 157 391 429 699 2005
Jun 913 887 422 537 2002
Mar 455 278 934 906 2004
May 669 995 726 324 2003
Nov 847 536 151 195 2002
Oct 321 950 278 173 2003
Sep 985 459 915 437 2002
添加回答
舉報
