我正在使用df.iterrows()遍历一列产品代码:
然后这些代码被发送到一个api并返回有关我的产品的各种详细信息。即新的和旧的销售价格。
每次迭代后,我都想将数据追加到数据帧。我应该在我的数据框中看到100行数据,但是我收到的只是最后产品代码的一行数据。
我想我需要创建第二个嵌套循环,在每次迭代时获取输出并将其附加到数据帧,但我不确定从何处开始。我的代码在下面。任何帮助都将不胜感激。
import numpy as np
import pandas as pd
accesskey = 'xxxx'
api = keepaAPI.API(accesskey)
df = pd.read_excel('C:/Users/xxxx.xlsx',
sheet_name = 'abebooks',
header = 0,
index_col = None,
usecols = "A:P",
convert_float = True)
for index, row in df.iterrows():
products = api.ProductQuery(row['xxx'])
product = products[0]
newprice = products[0]['data']['NEW']
newpricetime = products[0]['data']['NEW_time']
usedprice = products[0]['data']['USED']
usedpricetime = products[0]['data']['USED_time']
bsr = products[0]['data']['SALES']
bsrtime = products[0]['data']['SALES_time']
df = pd.DataFrame([[products[0]['title'],
products[0]['asin'],newprice[-1], usedprice[-1], bsr[-1],
products[0]['binding']]])
df2 = pd.DataFrame([], columns=list(["title", "Asin",
"New price", "Used price", "BSR", "Binding"]))
df.append(df2, ignore_index=True)