确定日期时间是否在python中的两个其他日期之间

时间:2017-03-14 01:49:44

标签: python pandas datetime

我有多个系列" start"并且"停止"在一组数据中的时间,并且想要查看特定的一组日期/时间是否落在给定的一组"开始/停止"之间。倍。我在python中使用pandas,并且我已经尝试将数据作为数据帧或时间序列 - 无法使用。我一直在使用这段代码:

 print (start1 < test1[0:LenS] < stop1).any()

(注意&#34; test1 [0:LenS]&#34;只是为了确保test1与start1和stop1的长度相同)我得到了这个错误:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

因为我试图使用.any(),所以我很困惑。谢谢你的帮助!

2 个答案:

答案 0 :(得分:0)

不幸的是,你无法像这样组合系列比较。

(start1 < test1[0:LenS]) & (test1[0:LenS]<stop)

应该可以同时测试多个条件。

答案 1 :(得分:0)

您可以将pandas.Series.between用作

test1[0:LenS].between(start1, stop1).any()