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

前端 未结 7 863
广开言路
广开言路 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:40

    You can use built-in strip() method for python strings.

    for each cell:

    text = str(illegal_text).strip()
    
    

    for entire data frame:

    dataframe = dataframe.applymap(lambda t: str(t).strip())
    
    0 讨论(0)
提交回复
热议问题