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?
lastIndexOf() The lastIndexOf() method returns the last index at which a given element can be found in the array, or -1 if it is not present.
Python3. Pandas iloc is used to retrieve data by specifying its integer index. In python negative index starts from end therefore we can access the last element by specifying index to -1 instead of length-1 which will yield the same result. Pandas iat is used to access data of a passed location.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With