d0rmLife d0rmLife - 2 years ago 91
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?

Answer Source

You could do


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download