I was trying to loop through dataframe rows in reverse order.
Based on row position rather than index name.
I though this code should work but its not.
for i, row in enumerate(df[::-1].iterrows()):
print (i)
As when I run it, it produces
0
1
2
3
4
5
rather than
5
4
3
2
1
0
I you accept reindexing, you can also do
for i, row in enumerate(df.reindex().sort_index(ascending=False):
print (i)
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