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
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?
Many thanks
答案 0 :(得分:10)
The following gives you the last index value:
df.index[-1]
Example:
In [37]:
df.index[-1]
Out[37]:
Timestamp('2015-03-25 00:00:00')
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')
答案 1 :(得分:1)
旧帖子,但是df.last_valid_index()
也可以。