I have a Pandas dataframe, df as follows:
0 1 2
0 k86e 201409 180
1 k86e 201410 154
2 k86e 201411 157
3 k86e 201412 153
4 k86e 201501 223
5 k86e 201502 166
6 k86e 201503 163
7 k86e 201504 169
8 k86e 201505 157
I know that in order to get the last 5 values of say column 2, I have to do:
df[2].tail()
This will return the values 157, 169, 163, 166, 233
.
However, I would like to skip the very last value which is = 157 and get the last five values before 157 e.g. 169, 163, 166, 233, 153
.
How can I do this?
Thanks in advance!