来自多索引的python系列loc值

来自多索引的python系列loc值,python,pandas,Python,Pandas,我有一个像这样的系列 2014 7 2014-07-01 -0.045417 8 2014-08-01 -0.035876 9 2014-09-02 -0.030971 10 2014-10-01 -0.027471 11 2014-11-03 -0.032968 12 2014-12-01 -0.031110 2015 1 2015-01-02 -0.028906 2

我有一个像这样的系列

2014  7   2014-07-01   -0.045417
      8   2014-08-01   -0.035876
      9   2014-09-02   -0.030971
      10  2014-10-01   -0.027471
      11  2014-11-03   -0.032968
      12  2014-12-01   -0.031110
2015  1   2015-01-02   -0.028906
      2   2015-02-02   -0.035563
      3   2015-03-02   -0.040338
      4   2015-04-01   -0.032770
      5   2015-05-01   -0.025762
      6   2015-06-01   -0.019746
      7   2015-07-01   -0.018541
      8   2015-08-03   -0.028101
      9   2015-09-01   -0.043237
      10  2015-10-01   -0.053565
      11  2015-11-02   -0.062630
      12  2015-12-01   -0.064618
2016  1   2016-01-04   -0.064852
我希望能够从日期中获取值。比如:

myseries.loc('2015-10-01')
并返回
-0.053565


索引是元组,格式为
(2016,1,2016-01-04)

您可以这样做:

In [32]:
df.loc(axis=0)[:,:,'2015-10-01']

Out[32]:
                          value
year month date                
2015 10    2015-10-01 -0.053565
您还可以通过每个级别的考试:

In [39]:
df.loc[(slice(None),slice(None),'2015-10-01'),]

Out[39]:
                          value
year month date                
2015 10    2015-10-01 -0.053565|
或者只需通过前两个索引级别:

In [40]:
df.loc[2015,10]

Out[40]:
               value
date                
2015-10-01 -0.053565
尝试:

print s.xs('2015-10-01',level=2,axis=0)
#year  datetime 
#2015  10   -0.053565
#Name: series, dtype: float64

print s.xs(7,level=1,axis=0)
#year  datetime  
#2014  2014-07-01   -0.045417
#2015  2015-07-01   -0.018541
#Name: series, dtype: float64