Python Error "UnicodeEncodeError: 'ascii' codec can't encode character u'\u03b1' in position 20: ordinal not in range(128)"

0 votes

I'm trying to write a to a csv file, I get the following error:

UnicodeEncodeError: 'ascii' codec can't encode character u'\u03b1' in position 20: ordinal not in range(128)

Line causing error:

df.to_csv('out.csv')
Jun 13, 2019 in Python by Kamal
1,525 views

2 answers to this question.

0 votes

use the sep argument of to_csv, to delimit by a tab:

df.to_csv(file_name, sep='\t')

To use a specific encoding (e.g. 'utf-8') use the encoding argument:

df.to_csv(file_name, sep='\t', encoding='utf-8')
answered Jun 13, 2019 by Rhea
0 votes
import csv

import sys
reload(sys)
sys.setdefaultencoding('utf8')

data = [["a", "b", u'\xe9']]

with open("output.csv", "w") as csv_file:
    writer = csv.writer(csv_file, quoting=csv.QUOTE_ALL)
    writer.writerows(data)
answered Jun 28, 2019 by anonymous

Hi. I am getting the following error when I ran this script:

NameError: name 'reload' is not defined

Use the following line to import the module

from importlib import reload

In Python 2, this was in build but in python, you've to use importlib.

Related Questions In Python

+1 vote
1 answer

(unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

You are getting this error because you ...READ MORE

answered Dec 31, 2019 in Python by Kalgi
• 50,570 points
342 views
0 votes
2 answers

Error: Speech to Text Codec cannot decode the bytes in position

import speech_recognition as sr r = sr.Recognizer() audio ='C\Users\Desktop\audiofile1.wav' with ...READ MORE

answered Nov 27, 2018 in Python by Nabarupa Das
262 views
0 votes
1 answer

i am normalizing the data set iris in python and get the error ::TypeError: 'numpy.float64' object is not callable

TRY THIS   #Nomalisation for i in names:     print(i)   ...READ MORE

answered Aug 19, 2019 in Python by Noel Deepak Palle
826 views
0 votes
0 answers

How to get the ASCII values of a character in python?

Is there a function for this task ...READ MORE

Jul 17, 2019 in Python by Waseem
• 4,520 points
51 views
0 votes
1 answer
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 539 views
0 votes
0 answers
+4 votes
6 answers
+1 vote
1 answer