3

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)

TypeError: to_excel() missing 1 required positional argument: 'excel_writer' here

After having typed this:

    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 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.

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

What do i need to do to fix this please?

Colleen
  • 143
  • 1
  • 3
  • 14

1 Answers1

5

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)
Jack Walsh
  • 562
  • 4
  • 14