On a related note, what would be the way to reverse both rows and columns?
df.iloc[::-1, ::-1]
I think for explain slicing is best check how working it in lists, here is used exactly same principe:
a[::-1] # all items in the array, reversed
a[1::-1] # the first two items, reversed
a[:-3:-1] # the last two items, reversed
a[-3::-1] # everything except the last two items, reversed
Pandas rows:
df.iloc[::-1] # all items in the array, reversed
df.iloc[1::-1] # the first two items, reversed
df.iloc[:-3:-1] # the last two items, reversed
df.iloc[-3::-1] # everything except the last two items, reversed
Btw, it is same like slice rows, get all columns with :
, but obviously omited, because working same:
df.iloc[::-1]
df.iloc[::-1, :]
....
Pandas columns - first :
means get all rows, then slice columns
df.iloc[:, ::-1] # all items in the array, reversed
df.iloc[:, 1::-1] # the first two items, reversed
df.iloc[:, :-3:-1] # the last two items, reversed
df.iloc[:, -3::-1] # everything except the last two items, reversed