In pandas 2 with the following code:
for time in tfo_dates:
    dt=pd.to_datetime(time)
    indx_time.append(df.index.get_loc(dt,method='nearest'))
I get this error:
TypeError: get_loc() got an unexpected keyword argument 'method'
This worked in version 1.5 but if we look at the version 2 documentation there is no method argument anymore.
What method I can use now to get nearest index of timestamp inside time index list?
you can use get_indexer
https://pandas.pydata.org/docs/reference/api/pandas.Index.get_indexer.html
The dt (the target) argument in below call, should be an index or a list. It cannot be a single value.
df.index.get_indexer(dt,method='nearest')
Make a note that, it returns an array object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With