类型错误:to_excel() 缺少 1 个必需的位置参数 - 尽管使用了 excel 编写器 [英] TypeError: to_excel() missing 1 required positional argument - despite using excel writer
问题描述
我在使用 Pandas 保存到 excel 时遇到问题,出现以下错误:
I've been having trouble saving to excel using pandas with the following error:
File "C:/Users/Colleen/Documents/Non-online code/kit_names.py", line 36, in save_sheet_names
pd.DataFrame.to_excel(writer)
类型错误:to_excel() 缺少 1 个必需的位置参数:'excel_writer'这里
TypeError: to_excel() missing 1 required positional argument: 'excel_writer' here
输入后:
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)
似乎正在使用作者,但显然我在某处出错了!(如果这是一个明显的问题,我深表歉意,因为我仍在了解熊猫)
Seemingly the writer is being used but evidently i have gone wrong somewhere! (I apologise if this is an obvious question as i am still getting my head around pandas)
Pycharm 发出一个小错误信号,这可能是导致此问题的原因,但是我不明白这实际上意味着什么,并且很难在网上找到提及.
Pycharm is signalling a minor error which may be what is causing this however i don't understand what it means in truth and struggled to find a mention online.
传递pandas.io.excel.excelwriter 而不是pandas.core.frame.dataframe.这是故意的吗?
passing pandas.io.excel.excelwriter instead of pandas.core.frame.dataframe. Is this intentional?
请问我需要做些什么来解决这个问题?
What do i need to do to fix this please?
推荐答案
只需将 to_excel()
函数更改为 df
Simply change the to_excel()
function to be caled on 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)
这篇关于类型错误:to_excel() 缺少 1 个必需的位置参数 - 尽管使用了 excel 编写器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!