to_excel attribute doesn't work

Multi tool use
to_excel attribute doesn't work
I opened an excel file as a df. I made some manipulations, added a column and now I'm trying to export the df to a different excel
Here's my code:
import pandas as pd
import numpy as np
import math
global df
pd.set_option('expand_frame_repr', False)
df = pd.read_excel('C:Userstal.elisbergDesktopאלטשולרsmartass.xlsx', None)
Ezer = df['Data']
vals = Ezer['abs hundred']
vals = list(vals)
teur_list = list(Ezer['Teur'])
rows = [None]*(len(teur_list))
vals = [str(round(x,2)) for x in vals if math.isnan(x) == False]
for i in range(len(vals)):
for j in range(len(teur_list)):
if vals[i] in teur_list[j]:
rows[j] = int(i)
df['Data']['Rows'] = pd.Series(rows, index=df['Data'].index)
writer = pd.ExcelWriter('PythonExport.xlsx')
df.to_excel(writer,'Sheet1')
writer.save()
the error : 'collections.OrderedDict' object has no attribute 'to_excel
Any suggestions as to why it is throwing an error?
dataframe
to_excel
to_excel
df = pd.read_excel('C:smartass.xlsx', 0)
should be ok to "translate" to dataframe the first sheet.– Vityata
Jul 2 at 12:53
df = pd.read_excel('C:smartass.xlsx', 0)
i pasted the wrong code, just updated it, if you can re-relate to my question
– Talis
Jul 3 at 7:24
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
The error is clear. You don't have a
dataframe
object, you have a ordereddict (which has noto_excel
method). By the way, the code you showed us has no line withto_excel
being called. Are you sure you posted the right part of the code?– RafaelC
Jul 2 at 12:51