在我当前的代码中,我正在迭代excel文件中一列的4500个单元格值.在每次迭代中,将单元格值添加到无效URL的两半之间,以形成有效URL.然后,我可以从URL请求特定单元格值的数据.在Python中,如何将每个单元格值的数据集附加到一个列表中?
import json
import requests
import pandas as pd
data = pd.read_excel('allstockdata.xlsx')
look = list(data["Meals"])
for i in look:
alist = [] #Line of Interest
i = str(i)
alldata = json.loads(requests.get(url1half1 + i + url1half2).text) + json.loads(requests.get(url2half1 + i + url2half2).text) #Gets data in form of single nested dictionary in list for each iteration [{}]
alist.append(alldata) # Line of Interest
print(alist)
2次迭代的当前输出:
[[{'Fruit': 'Apple', 'Protein': 'Steak', 'Vegetable': 'Cabbage' }]]
[[{'Fruit': 'Pear', 'Protein': 'Chicken', 'Vegetable': 'Spinach'}]]
所需输出
[
[{'Fruit': 'Apple', 'Protein': 'Steak', 'Vegetable': 'Cabbage' }],
[{'Fruit': 'Pear', 'Protein': 'Chicken', 'Vegetable': 'Spinach'}],
]