Python 访问dataframe的最后一个索引值
我有两种产品的数据帧(df)示例:Python 访问dataframe的最后一个索引值,python,pandas,Python,Pandas,我有两种产品的数据帧(df)示例: BBG.XAMS.FUR.S BBG.XAMS.MT.S date 2014-10-23 -2368.850388 0.000000 2014-10-24
BBG.XAMS.FUR.S BBG.XAMS.MT.S
date
2014-10-23 -2368.850388 0.000000
2014-10-24 6043.456178 0.000000
2015-03-23 -0.674996 -0.674997
2015-03-24 82.704951 11.868748
2015-03-25 -11.027327 84.160210
是否有方法仅检索数据帧的最后一个索引值。因此,在本例中,我需要检索的日期值是2015-03-25?以下给出了最后一个索引值:
df.index[-1]
例如:
In [37]:
df.index[-1]
Out[37]:
Timestamp('2015-03-25 00:00:00')
或者您可以访问尾部的index属性
:
In [40]:
df.tail(1).index[0]
Out[40]:
Timestamp('2015-03-25 00:00:00')
旧帖子,但
df.last\u valid\u index()
也可以使用