下面是实际代码,然后报错:ValueError: Writing 0 cols but got 4 aliases。
for i in range(301265, 301270):
sym = "sz" + str(i)
if sb.top_holders(sym)["data"]["items"] != []:
chg, hd_ratio, hd_quantity = getTop_holders_chg(sym)
res.append([sym, chg, hd_ratio, hd_quantity / 10000])
pd.DataFrame(res).to_csv(
"all301265_301270.csv",
header=["stock code", "change ratio", "hold ratio", "hold quantity(10k)"],
index=False
)
问题解决:实际上就是for循环中没有抓取到任何数据,然后写入csv时报错,所以不是代码的问题,for循环如果抓取到数据就不报错了。



