I'm new to stackoverflow and I have research but have not find a satisfying answer.
I understand that I can get a row index by using df.iterrows() to iterate through a df. But what if I want to get a row position instead of row idx. What method can I use?
Example code that I'm working on is below:
df = pd.DataFrame({'month': ['Jan', 'Feb', 'March', 'April'],
'year': [2012, 2014, 2013, 2014],
'sale':[55, 40, 84, 31]})
df = df.set_index('month')
for idx, value in df.iterrows():
print(idx)
How can I get an output of:
0
1
2
3
Thanks!
df.index
– Freerdf.iterrows()
" – Boleslaw