Need to read a dataframe line by line



Hi, I have a requirement to process the Excel file.
Have taken this file to dataframe.
Now I need to process each line by line from dataframe.

Here is what I am doing

for index, row in df.iterrows():

 headers  = {"Content-Type": "application/json"}

from requests.auth import HTTPBasicAuth‘URL’, auth=HTTPBasicAuth(‘Username’, ‘Pass’),headers=headers, data=json.dumps({

Here the ‘0’ th Index is escaping and next line is taking.(First line in dataFrame)

May I know what is the reason.

Thanks in Advance


Hi Sachin,

I’ve pasted an example below and it correctly picks up index 0 entry.
A plausible reason why you might be seeing the odd behaviour is due to incorrect indentation (in particular around the for loop)

Python 3.6.5 (default, Jul  8 2018, 12:45:30) 

In[2]: import pandas as pd
  ...: d = {'col1':['DMD','DYSF'], 'col2':[33,44]}
  ...: df = pd.DataFrame(d)
  ...: for index, row in df.iterrows():
  ...:     print(row['col1'])
  ...:     print(index)

Also, when pasting code (in particular Python which relies on indentation), please use a code block. The BBCode markdown format is quite handy for this. Here’s a reference guide: