close

[Solved] UnicodeDecodeError: ‘utf8’ codec can’t decode byte 0x9c

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error UnicodeDecodeError: ‘utf8’ codec can’t decode byte 0x9c in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How UnicodeDecodeError: ‘utf8’ codec can’t decode byte 0x9c Error Occurs?

Today I get the following error UnicodeDecodeError: ‘utf8’ codec can’t decode byte 0x9c in python.

How To Solve UnicodeDecodeError: ‘utf8’ codec can’t decode byte 0x9c Error ?

  1. How To Solve UnicodeDecodeError: 'utf8' codec can't decode byte 0x9c Error ?

    To Solve UnicodeDecodeError: 'utf8' codec can't decode byte 0x9c Error Changing the engine from C to Python did the trick for me.
    Engine is C:

  2. UnicodeDecodeError: 'utf8' codec can't decode byte 0x9c

    To Solve UnicodeDecodeError: 'utf8' codec can't decode byte 0x9c Error Changing the engine from C to Python did the trick for me.
    Engine is C:

Solution 1


the first,Using get_encoding_type to get the files type of encode:

import os    
from chardet import detect

# get file encoding type
def get_encoding_type(file):
    with open(file, 'rb') as f:
        rawdata = f.read()
    return detect(rawdata)['encoding']

the second, opening the files with the type:

open(current_file, 'r', encoding = get_encoding_type, errors='ignore')

Solution 2


Changing the engine from C to Python did the trick for me.

Engine is C:

pd.read_csv(gdp_path, sep='\t', engine='c')

‘utf-8’ codec can’t decode byte 0x92 in position 18: invalid start byte

Engine is Python:

pd.read_csv(gdp_path, sep='\t', engine='python')

No errors for me.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read