import time import akshare as ak import pandas as pd with open("aa.txt","r") as fp: fp.readline() for i in fp: b = i.split() stock_zh_a_daily_hfq_df = ak.stock_zh_a_daily(symbol=b[0], adjust="hfq") a = stock_zh_a_daily_hfq_df # 定义文件 file_name=b[0]+".xlsx" writer = pd.ExcelWriter(file_name, encoding="utf-8-sig") a.to_excel(writer, "sheet1") writer.save() print("数据保存成功")
时间: 2024-01-13 08:03:24 浏览: 112
import pandas as pd.docx
你的代码中存在一个缩进错误,请将 `import` 和 `with` 语句的缩进修改为正确的格式,即:
```
import time
import akshare as ak
import pandas as pd
with open("aa.txt","r") as fp:
fp.readline()
for i in fp:
b = i.split()
stock_zh_a_daily_hfq_df = ak.stock_zh_a_daily(symbol=b[0], adjust="hfq")
a = stock_zh_a_daily_hfq_df
# 定义文件
file_name=b[0]+".xlsx"
writer = pd.ExcelWriter(file_name, encoding="utf-8-sig")
a.to_excel(writer, "sheet1")
writer.save()
print("数据保存成功")
```
另外,如果你的代码仍然出现 `ExcelWriter.__new__() got an unexpected keyword argument 'encoding'` 的错误,请检查你使用的 `pandas` 版本是否较老,如果是,可以尝试更新到最新版本。
阅读全文