gpt4 book ai didi

python - 类型错误 : to_excel() missing 1 required positional argument - despite using excel writer

转载 作者:行者123 更新时间:2023-12-05 02:15:33 35 4
gpt4 key购买 nike

我在使用 pandas 保存到 excel 时遇到了以下错误:

File "C:/Users/Colleen/Documents/Non-online code/kit_names.py", line 36, in save_sheet_names
pd.DataFrame.to_excel(writer)

TypeError: to_excel() 缺少 1 个必需的位置参数:'excel_writer' 这里

输入后:

    df =pd.DataFrame(arr)
y=os.path.basename(os.path.normpath(path))
new_path = r"C:\Users\Colleen\Documents\\"+y
writer = pd.ExcelWriter(new_path, engine='xlsxwriter')
pd.DataFrame.to_excel(writer)

貌似作者被利用了,但显然我哪里出错了! (如果这是一个明显的问题,我深表歉意,因为我仍然在关注 Pandas )

Pycharm 发出一个小错误的信号,这可能是造成这种情况的原因,但我不明白它实际上意味着什么,并且很难在网上找到提及。

passing pandas.io.excel.excelwriter instead of pandas.core.frame.dataframe. Is this intentional?

请问我需要做什么来解决这个问题?

最佳答案

只需将 to_excel() 函数更改为在 df

上调用
df =pd.DataFrame(arr)
y=os.path.basename(os.path.normpath(path))
new_path = r"C:\Users\Colleen\Documents\\"+y
writer = pd.ExcelWriter(new_path, engine='xlsxwriter')
df.to_excel(writer)

关于python - 类型错误 : to_excel() missing 1 required positional argument - despite using excel writer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51597773/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com