对dataframe单元格赋值(三)

大家好!

img

我将上图中的excel表格导入python生成一个Dataframe
现在我要使用Tushare的行情查询A列中每个股票在日期start_date的收盘价,并填入start_date_price列的相应行中;

以下是我的代码:

df = pd.read_csv('D:/private/stock investment/st_research.csv')

Code=list(df['ts_code'])

Start_date=list(df['start_date'])

for x,y in zip(Code,Start_date):
result=pro.daily(ts_code=x, trade_date=y)
#将查询到的收盘价close填入start_date_price列的相应行中
df.loc[df[df.ts_code == x].index.tolist(),'start_date_price'] = result.loc[0,'close']

print(df.head())

运行结果报错,如下图:

img

img

请问倒数第二行对dataframe单元格赋值的代码有什么问题?应该如何修改?
谢谢!

result没用行索引为0的?