How to remove illegal characters so a dataframe can write to Excel

前端 未结 7 888
广开言路
广开言路 2020-12-03 05:14

I am trying to write a dataframe to an Excel spreadsheet using ExcelWriter, but it keeps returning an error:

openpyxl.utils.exceptions.IllegalCharacterError
         


        
7条回答
  •  鱼传尺愫
    2020-12-03 05:23

    If you're still struggling to clean up the characters, this worked well for me:

    import xlwings as xw
    import pandas as pd
    df = pd.read_pickle('C:\\Users\\User1\\picked_DataFrame_notWriting.df')
    topath = 'C:\\Users\\User1\\tryAgain.xlsx'
    wb = xw.Book(topath)
    ws = wb.sheets['Data']
    ws.range('A1').options(index=False).value = df
    wb.save()
    wb.close()
    

提交回复
热议问题