访问数据帧的最后一个索引值 [英] Access last index value of dataframe
本文介绍了访问数据帧的最后一个索引值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2种产品的示例数据框(df):
I have an example dataframe (df) for 2 products:
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?
Is there a way to retrieve the last index value of a dataframe only. So in this example the date value I need retrieved is 2015-03-25?
非常感谢
推荐答案
以下内容为您提供了最后一个索引值:
The following gives you the last index value:
df.index[-1]
示例:
In [37]:
df.index[-1]
Out[37]:
Timestamp('2015-03-25 00:00:00')
或者您可以访问tail
的索引属性:
Or you could access the index attribute of the tail
:
In [40]:
df.tail(1).index[0]
Out[40]:
Timestamp('2015-03-25 00:00:00')
这篇关于访问数据帧的最后一个索引值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文