UnicodeDecodeError: & #39; UTF-8 & #39; codec can & #39; t decode byte 0xce in position 52: invalid continuation byte, continuation

Source: Internet
Author: User

UnicodeDecodeError: 'utf-8 'codec can' t decode byte 0xce in position 52: invalid continuation byte, continuation

Code:

df_w = pd.read_table(    r'C:\Users\lab\Desktop\web_list_n.txt', sep=',', header=None)

 

This error occurs when I use the read_table method of pandas to read local files:

UnicodeDecodeError: 'utf-8 'codec can' t decode byte 0xce in position 52: invalid continuation byte

Query and find the two most common and stubborn errors in Python encoding:

UnicodeEncodeError: 'ascii 'codec can't encode characters in position 0-1: ordinal not in range (128)

UnicodeDecodeError: 'utf-8 'codec can' t decode bytes in position 0-1: invalid continuation byte

That is, the encoding and decoding problem. My error is that 'utf-8' cannot decode the byte at location 52 (0xce), that is, the byte exceeds the UTF-8 representation range, for more information about encoding and decoding, see https://segmentfault.com/a/1190000004625718

 

Solution:

df_w = pd.read_table(    r'C:\Users\lab\Desktop\web_list_n.txt', encoding='ISO-8859-1', sep=',', header=None)

That is, when reading data, explicitly add the encoding method encoding = 'iso-8859-1 '. You can also try other encoding methods.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.