I have an indexed pandas dataframe. By searching through its index, I find a row of interest. How do I find out the iloc of this row?
Example:
dates = pd.date_range('1/1/2000', periods=8) df = pd.DataFrame(np.random.randn(8, 4), index=dates, columns=['A', 'B', 'C', 'D']) df A B C D 2000-01-01 -0.077564 0.310565 1.112333 1.023472 2000-01-02 -0.377221 -0.303613 -1.593735 1.354357 2000-01-03 1.023574 -0.139773 0.736999 1.417595 2000-01-04 -0.191934 0.319612 0.606402 0.392500 2000-01-05 -0.281087 -0.273864 0.154266 0.374022 2000-01-06 -1.953963 1.429507 1.730493 0.109981 2000-01-07 0.894756 -0.315175 -0.028260 -1.232693 2000-01-08 -0.032872 -0.237807 0.705088 0.978011 window_stop_row = df[df.index < '2000-01-04'].iloc[-1] window_stop_row Timestamp('2000-01-08 00:00:00', offset='D') #which is the iloc of window_stop_row?
df.index.get_loc(window_stop_row.name)