Need to read a dataframe line by line

dataframe
python

#1

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
r=requests.post(‘URL’, auth=HTTPBasicAuth(‘Username’, ‘Pass’),headers=headers, data=json.dumps({
‘name’:row[“Name”],
‘domainId’:‘7319ca59-f9d4-4f86-9eaf-a359691b378b’,
‘typeId’:‘00000000-0000-0000-0000-000000011001’
}))
print(r.text)

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


#2

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)
  ...: 
DMD
0
DYSF
1

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: https://www.bbcode.org/reference.php