我有一个名为table1
的数据透视表,如下所示:
Volume
Site TripDate
003l 1990-06-10 2354.043820
1991-07-26 2745.673779
1993-10-08 22789.790846
1994-11-20 23072.306665
1995-04-24 25203.740194
1996-02-13 16505.985301
1996-04-15 8257.426317
1996-09-12 9148.369265
1997-02-13 10014.168593
1997-04-20 11154.686365
1997-08-23 13064.444117
1997-11-06 13704.596573
1998-04-15 14358.140459
1999-05-04 18100.457859
2000-03-17 22910.600843
2000-06-01 617.621794
2001-10-05 882.738323
016l 1990-06-10 962.070643
1991-07-26 761.409178
1993-10-08 475.038362
1994-11-20 312.339596
1995-04-24 11569.523232
1996-02-13 15272.175019
1996-04-15 13542.057394
1996-09-12 14556.930737
1997-02-13 18905.265710
1997-04-20 19832.509861
我感兴趣的是使用最早的体积计算计算每个站点的体积百分比作为"理论值"规范化数据。对于每个站点,有没有办法直接从数据透视表中为最早的体积计算(即1990-06-10)定义变量?
%Volume的示例公式为:
%Volume=(V_survey-V_1990)/(V_1990)
我已经厌倦了基于一级索引的子集:
test = table1[table1[['TripDate']]==1990-06-10]
但是,它会引发以下错误:
KeyError: "['TripDate'] not in index"
如果我使用list(table1.index.names)
检查索引的名称,则返回:
['Site', 'TripDate']