Noobie Noobie - 1 year ago 58
Python Question

how to slice a dataframe from the end to the beginning?

I am slicing a dataframe like this:

for i in xrange(0,len(df),100000):
print("slice %d!!!!" % i)
slice= df.iloc[i:(i+100000)]


I would like now to get
100k
slices from the end to the beginning of the df (without necessarily sorting my dataframe).

How can I do that?

Thanks!

Answer Source

Simply use tail:

df.tail(100000)