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

前端 未结 7 866
广开言路
广开言路 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())
    

提交回复
热议问题