我有一个pandas DataFrame“df”如下:
lat lon time
ID
48202 42.5040 -70.5419 731800.5514
48202 42.4956 -70.5539 731801.6319
48202 42.4927 -70.5830 731802.7188
48202 42.5028 -70.6010 731802.8014
48202 42.5168 -70.5966 731803.8944
48202 42.5202 -70.5746 731804.9729
48202 42.5115 -70.5528 731804.0521
48202 42.5020 -70.5427 731805.1410
... ... ... ...
和两个特定值:
t0=731801
t1=731803
现在我要提取DataFrame“df”的部分,其“时间”值介于t0和t1之间,如下所示:
lat lon time
ID
48202 42.4956 -70.5539 731801.6319
48202 42.4927 -70.5830 731802.7188
48202 42.5028 -70.6010 731802.8014
48202 42.5168 -70.5966 731803.8944
我该怎么做?我使用“df.ix”方法
df=df.ix[df['time']<=t1 and df['time']>=t0]
但它不起作用。错误消息:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
答案 0 :(得分:1)
df_masked = df[(df.time <= t1) & (df.time >= t0)]