I have a Pandas dataframe which is indexed by a DatetimeIndex:
DatetimeIndex: 53732 entries, 1993-01-07 12:23:5
This simple method will return the (integer index of the) TimeSeriesIndex entry closest to a given datetime object. There's no need to copy the index to a regular column - simply use the .to_pydatetime method instead.
import numpy as np
i = np.argmin(np.abs(df.index.to_pydatetime() - image_time))
Then you simply use the DataFrame's .iloc indexer:
df.iloc[i]
Here's a function to do this:
def fcl(df, dtObj):
return df.iloc[np.argmin(np.abs(df.index.to_pydatetime() - dtObj))]
You can then further filter seamlessly, e.g.
fcl(df, dtObj)['column']