python pandas - 将行的索引检索为整数值

时间:2016-12-31 18:11:15

标签: python pandas

我有以下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

我按照以下方式在感兴趣的时间检索一行:

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

它正确返回

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

我现在想要将该行的索引检索为整数值。即在这个例子中它应该是2(第3行)。我该怎么做呢?我曾经尝试使用get_loc,但我有点困惑

0 个答案:

没有答案