Pandas get_loc with datetimeindex failing
问题 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