Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88066

Incorrect character in saving process for excel

$
0
0

I'm creating a new coloumn and this new file and want to save. But in there excel file a coloumn have a character. How can I skip this line the save process or change line to a correct character?

import pandas as pd

path = '/My Documents/Python/'
fileName = "test.xlsx"


# open the excel file
ef = pd.ExcelFile(path+fileName)

# read the contents
df = pd.read_excel(path+fileName, sheet_name=ef.sheet_names[0])
print(df['Content'])
print(df['Engine'])

i = 1
for test in df['Content']:
    try:
        print(i)
        print(test)
    except:
        print("An exception occurred")
        break
    i += 1

df['Test'] = 'value'
df.to_excel('My Documents/Python/Test_NEW.xlsx')

Error message

data, consumed = self.encode(object, self.errors)
    UnicodeEncodeError: 'utf-8' codec can't encode character '\ude7c' in position 470: surrogates not allowed

Viewing all articles
Browse latest Browse all 88066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>