我有一个时间索引数据帧,我想找出与给定时间最近的时间匹配的行号
例如:
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,在Windows101909上的Python3.8.1 64位上
我做错了什么
目前没有回答
相关问题 更多 >
编程相关推荐