0

I have the following Pandas DataFrame:

                        open     high      low    close  volume
timestamp                                                      
2005-03-06 17:00:00  1225.75  1226.25  1225.00  1225.50  1668.0
2005-03-06 17:30:00  1225.75  1227.50  1225.75  1227.00  1603.0
2005-03-06 18:00:00  1227.00  1227.50  1226.75  1227.25   590.0
2005-03-06 18:30:00  1227.25  1227.50  1226.75  1226.75   213.0
2005-03-06 19:00:00  1227.00  1227.00  1226.25  1226.25   521.0

I retrieve a row at a time of interest in the following way:

t_of_interest = dt (2005, 3, 6, 18)
price_data.loc[t_of_interest]

It correctly returns

open      1227.00
high      1227.50
low       1226.75
close     1227.25
volume     590.00
Name: 2005-03-06 18:00:00, dtype: float64

I would now like to retrieve the index of that row as an integer value. Ie in this example it should be 2 (the 3rd row). How would i go about to do that? I've forayed into using get_loc but i am a bit confused

jim jarnac
  • 4,804
  • 11
  • 51
  • 88
  • Have you checked out this [answer](http://stackoverflow.com/a/35138807/5839618)? Are you searching with the index or with the open, high, etc. values in the series? – 3novak Dec 31 '16 at 18:21
  • 1
    `price_data.index.get_loc(dt(2016, 12, 30, 15))` should work. Have you tried that? – ayhan Dec 31 '16 at 18:21
  • @ayhan ok yes.. Sorry was a bit confused – jim jarnac Dec 31 '16 at 18:27
  • No problem. I am redirecting this question to an older question that has the same answer then. – ayhan Dec 31 '16 at 18:36

0 Answers0