python - 带有 datetimeindex 的 Pandas get_loc 失败
问题描述
我有一个时间索引数据框,我想找到与给定时间最接近的行号。
例如,:
import pandas as pd
findtime = pd.Timestamp('2019-12-12 10:19:25', tz='US/Eastern')
start = pd.Timestamp('2019-12-12 0:0:0', tz='US/Eastern')
end = pd.Timestamp('2019-12-13 0:0:0', tz='US/Eastern')
testindex = pd.date_range(start, end, freq='5s')
testindex.get_loc(findtime, method='nearest')
但是,这会引发错误:
UFuncTypeError: ufunc 'subtract' cannot use operands with types dtype('<M8[ns]') and dtype('O')
如果重要的话,这是 Pandas 1.0.1,在 Windows 10 1909 上的 python 3.8.1 64 位上。
我在这里做错了什么?
解决方案
推荐阅读
- c# - MediatR 取消发布后续消息
- pandas - 根据特定列值的升序检索数据框中的行
- ios - Assets.xcassets XCode 11 中的图像本地化不起作用
- android - WiFiManager EnableNetwork() 在 android 10 上不起作用
- javascript - 用参数调用对象方法的 Ramda 函数?
- highcharts - HighCharts:我可以直接调用导出函数吗?
- android - 如何从自定义列表中在 Room 中制作 TypeConverter?
- scala - 在 Scala 中为泛型 T(如果可用)获取 Numeric[T]
- .net - 如何仅在 VB.Net 中检测移动设备?
- css - 有没有办法说两个相邻的 CSS 网格列总共占用了一定的空间?