【发布时间】:2016-12-28 07:33:07
【问题描述】:
我有 pandas 数据透视表 merge2,看起来像:
Site TripDate Volume Early_Vol Percent_Vol
0 024l 2004-12-02 1117.134948 1117.134948 0.000000
1 024l 2005-05-07 390.980708 1117.134948 -0.650015
2 024l 2006-10-07 321.110175 1117.134948 -0.712559
3 024l 2007-10-13 527.631767 1117.134948 -0.527692
4 024l 2008-02-02 597.165065 1117.134948 -0.465449
然后我将merge2 子集化为sub1
sub1 = merge2[['Site','TripDate','Percent_Vol']]
sub1= sub1.set_index(['Site','TripDate'])
sub1 看起来像:
Percent_Vol
Site TripDate
024l 2004-12-02 0.000000
2005-05-07 -0.650015
2006-10-07 -0.712559
2007-10-13 -0.527692
2008-02-02 -0.465449
然后,我将sub1 拆分为t 看起来像:
Percent_Vol
Site 024l 029l 033l 035l_r 035l_s 041r_r
TripDate
2004-06-01 NaN NaN NaN NaN NaN NaN
2004-11-13 NaN NaN NaN NaN NaN NaN
2004-12-02 0.000000 0.000000 0.000000 0.0 0.000000 0.000000
2005-05-07 -0.650015 -0.290539 -0.300276 -1.0 -0.075511 -0.298801
2006-10-07 -0.712559 -0.769020 -0.393304 -1.0 -0.520052 -0.284686
在t(即Percent_Vol 和Site)中,我的列名似乎有两个级别,而我只有Site。有没有办法将列名更改为 Site?
【问题讨论】: