【发布时间】:2017-02-01 10:58:37
【问题描述】:
我可以通过首先将 datetime created 列设置为索引并对数据框进行切片来在两个日期之间选择 pandas 数据框。但现在我想做一个涉及额外日期时间列“修改日期”的新查询,即:
df = df.set_index(['created'])
print (df)
name modifieddate
created
2014-01-01 16:07:07 john 2014-01-01 16:07:07
2014-01-04 16:07:07 harold 2014-01-04 16:07:07
2014-01-04 16:07:07 clara 2014-01-04 18:07:07
2014-01-05 16:07:07 emily 2014-01-06 16:07:07
2014-01-08 16:07:07 smiths 2014-01-08 16:07:07
2014-01-09 20:07:07 clara 2014-01-09 20:07:07
2014-01-10 18:07:07 clara 2014-01-10 18:07:07
2014-01-10 16:07:07 john 2014-01-11 16:07:07
选择created 和modifieddate 相等且位于给定日期时间2014-01-04 16:07:07 和2014-01-10 16:07:07 之间的行:
name modifieddate
created
2014-01-04 16:07:07 harold 2014-01-04 16:07:07
2014-01-08 16:07:07 smiths 2014-01-08 16:07:07
2014-01-09 20:07:07 clara 2014-01-09 20:07:07
【问题讨论】: