问题
I have a time-indexed dataframe, and I want to find what row number matches the closest time to a given time.
For example,:
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')
However, this throws an error:
UFuncTypeError: ufunc 'subtract' cannot use operands with types dtype('<M8[ns]') and dtype('O')
If it matters, this is Pandas 1.0.1, on python 3.8.1 64-bit on Windows 10 1909.
What am I doing wrong here?
来源:https://stackoverflow.com/questions/60330253/pandas-get-loc-with-datetimeindex-failing