d0rmLife d0rmLife - 5 months ago 10x
Python Question

Can a DataFrame be "reverse indexed"?

Is there a builtin function to "reverse index" a pandas data frame? For example, if the data frame represents time series data, and we iterate through the time series data, is there a builtin function to access the date for a given value?


# Let series be a pandas data frame with a column header and row labels as dates.
for i in series:
# do stuff
if something:
get date for this i

Or is it necessary to just go through the data in a different fashion?


You could do


If there can be multiple dates for the same value, you could do series[series==i].index.tolist()