根据一个列数据过滤行和列

时间:2017-11-17 20:42:14

标签: python pandas

如何根据第一列的值选择数据(突出显示)。我的意思是我需要选择以特定时间开始和结束的数据,因为我不知道S08S09中的数据等等。

在此之后,我将获取每列的前100个值的mean(),然后依此类推。

g3=df.loc[(df.timeInterval>=171) & (df.timeInterval<=174) & (df.timeInterval>=181) & (df.timeInterval<=184) & (df.timeInterval>=191) & (df.timeInterval<=194) & (df.timeInterval>=201) & (df.timeInterval<=204),['S08','S09','S41']]
g3

enter image description here

1 个答案:

答案 0 :(得分:0)

我无法让pandas索引按预期工作,但您的意思是这样吗?

df = pd.DataFrame(np.array(np.random.rand(10, 2)), columns = ['timeInterval', 'value'])

df2 = df['value'][df.timeInterval >= 0.3][df.timeInterval <= 0.7]
df2