Python Forum
pandas writer create "corrupted" file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pandas writer create "corrupted" file
#1
Sad 
Hello,
I recently start to learn Python (I use Jupyter), and I do a code which scrap data from several urls. Depending on the frames, I write data in excel files and sheets.
Everything looks fine, but when I open the excel file I have an error message to recover the data like this one :
[Image: lIt7y.png]

If I accept, I can see the data correctly but I don't understand why I have this message.
The problem won't appears when the Excel file has only one sheet.

Do you know what can be the cause ?

Thank you.

Example of loop I used :
df = pd.read_html(xurl)
 
    writerhome = ExcelWriter(pathhome+'\\'+home+'_v1.xlsx') 
 
 
    print("******START COPY DATA******")
    for idx,table in enumerate(df) :
        print("************")
        print(idx) #dataframe id in the url
        print(table) #data from the dataframe
 
        if idx >2 and idx <10 : #Tableau home
            print('Copy in '+home+'_v1.xlsx sheetname_home : '+(dictsheets[idx]))
            df[idx].to_excel(writerhome, sheet_name=dictsheets[idx], index=True)
            writerhome.save()
Reply
#2
Use df.to_excel and you should not loop like this in Pandas(has own method for this).
Here are simpler test,see if this work.
Install openpyxl if you have not pip install openpyxl
import pandas as pd


df = pd.DataFrame(
    [[11, 21, 31], [12, 22, 32], [31, 32, 33]],
    index=["one", "two", "three"],
    columns=["a", "b", "c"],
)

print(df)
df.to_excel('to_excel.xlsx', sheet_name='new_sheet')
Output:
a b c one 11 21 31 two 12 22 32 three 31 32 33
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create Choices from .ods file columns cspower 3 614 Dec-28-2023, 09:59 PM
Last Post: deanhystad
  Recommended way to read/create PDF file? Winfried 3 2,902 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  Use PM4PY and create working file thomaskissas33 0 678 Nov-14-2023, 06:53 AM
Last Post: thomaskissas33
  Create csv file with 4 columns for process mining thomaskissas33 3 760 Nov-06-2023, 09:36 PM
Last Post: deanhystad
  Better python library to create ER Diagram by using pandas data frames as tables klllmmm 0 1,145 Oct-19-2023, 01:01 PM
Last Post: klllmmm
  Downloaded file corrupted emont 5 840 Oct-01-2023, 11:32 AM
Last Post: snippsat
  create exe file for linux? korenron 2 985 Mar-22-2023, 01:42 PM
Last Post: korenron
  my first file won't create itself MehHz2526 2 906 Nov-27-2022, 12:58 AM
Last Post: MehHz2526
  Csv writer meaning of quoting mg24 2 1,162 Oct-01-2022, 02:16 PM
Last Post: Gribouillis
  Create multiple/single csv file for each sql records mg24 6 1,413 Sep-29-2022, 08:06 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020