【发布时间】:2015-06-13 05:02:53
【问题描述】:
我从时间序列创建了一个多索引熊猫系列,现在我想读取其中的数据。在我看到的所有示例中,该系列的列或级别都已命名。但是,在我的系列中并非如此。在这个多索引中,第一级是日期,第二级是一天中的小时。数据列有我要读取的值。
从我的系列中获取我想要的数据的最简单方法是什么?下面的代码应该很容易解释。
import pandas as pd
import numpy as np
n = 1000
t = pd.date_range(start ='2012-01-01', periods=n, freq='10T')
x = np.random.randn(n)
df = pd.Series(data=x, index=t)
df1 = df[(df > 1) & (df < 1.5)]
df2 = df1.groupby([df1.index.date, df1.index.hour]).count()
df2.head(15)
#How do I get the data out of df2?
#For example, I want to read the data for '2012-01-02 01:00'
【问题讨论】:
标签: python pandas multi-index