0

I have an excel file, which contains only one sheet, called 'Sheet1'. What I want to do is read all the rows from each column to send that data to a request in an API. I'm only able to send the last data of the worksheet, using this code:

my_table = pd.read_excel("Myexcel.xlsx")
      
for i, name in enumerate(my_table["Name"]):  
  categ = str(int(my_table.loc[i, "CategoryId"]))
  brd = my_table.loc[i, "BrandName"]
  des = my_table.loc[i, "Description"]
  titl = my_table.loc[i, "Title"]

payloads = {"Name": name, "CategoryId": categ, "BrandName": brd, "Description": des, "Title": titl}

response = requests.post(url, headers=headers, json=payloads)
response = response.json()

What I want to do is send all the values. I couldn't specify how many lines there are, because the amount of data in the file can be changed, either more or less. I would like to do this in python

LaraF
  • 29
  • 6

1 Answers1

0

It looks to me like you are assigning name, Category.id .... Title to values associated with rows, and then not doing anything with them before reassigning the values again. if the comments I'm reading [here] are to be believed, it seems you can make the elements of your payload lists, where the elements in the list are elements from your row/xlsx file.

Maybe try something like

my_table = pd.read_excel("Myexcel.xlsx")
      
for i, name in enumerate(my_table["Name"]):  
  categ.append(str(int(my_table.loc[i, "CategoryId"])))
  brd.append(my_table.loc[i, "BrandName"])
  des.append(my_table.loc[i, "Description"])
  titl.append(my_table.loc[i, "Title"])

payloads = {"Name": name, "CategoryId": categ, "BrandName": brd, "Description": des, "Title": titl}

response = requests.post(url, headers=headers, json=payloads)
response = response.json()

Can't promise anything though, sorry! This is the route I would try, but I don't know if it will lead anywhere. I'm going to post another link that may contain helpful discussion here

  • I understood what you meant. but somehow I managed to send the values ​​I wanted to the api without adding the append. I didn't understand why. – LaraF Jun 02 '22 at 03:35