0

I have a string column in my pandas dataframe. I am facing error when i try to export this column to an excel file. Am able to export the dataframe if i delete that column.

I tried to decode all the values in that string column.I got the following error:

UnicodeDecodeError: 'ascii' codec can't decode byte 0x81 in position 16: ordinal not in range(128)

I debugged a little and found a column value in that particular column.I am not able to decode this value ('Einen Use case fr Brems-').

I took that value and tried the following code , facing error again.

#!/usr/bin/python
# -*- coding: utf-8 -*-

text = 'Einen Use case fr Brems-'

print text.decode()

1) i have tried adding following lines as well.

import sys  

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

2) I tried this in my system:

import sys
print sys.getdefaultencoding()

i got 'ascii' as output.

Sindhu
  • 36
  • 3
  • Please follow the answer, it might lead to a resolution : https://stackoverflow.com/questions/21129020/how-to-fix-unicodedecodeerror-ascii-codec-cant-decode-byte, otherwise let us know – Aman Raparia Mar 22 '19 at 07:13
  • This is probably because you are decoding your file with a wrong format. If you are on Linux you can find out your file's encoding format using `file -i` and then use a different decoding format in your file input functions. – Farhood ET Mar 22 '19 at 07:14
  • @AmanRaparia I referred those answers too , didn't solve my issue. – Sindhu Mar 22 '19 at 08:44
  • @FarhoodET am running the code in windows machine , i got 'ascii' as my default encoding format. – Sindhu Mar 22 '19 at 08:49
  • @sindhu read this https://stackoverflow.com/questions/3710374/get-encoding-of-a-file-in-windows , and change your encoding type for your panda DataFrame method. – Farhood ET Mar 22 '19 at 08:54

0 Answers0