"Python" read the CVS file error: Unicodedecodeerror: ' Utf-8 ' codec can ' t decode byte 0xb1 in position 6:invalid start byte

Source: Internet
Author: User

There are now files in the data.csv file encoding format: ANSI

Data.csv

1|1|1| Beijing 2|1|2| Tianjin 3|1|3| Shanghai 4|1|4| Chongqing city 5|1|5| Shijiazhuang City 6|2|5| Tangshan 7|3|5| Qinhuangdao Shi 8|4|5| Hanhan 9|5|5| Xingtai 10|6|5| Baoding 11|7|5| Zhangjiakou 12|8| 5| Chengde 13|9|5| Cangzhou 14|10|5| Langfang 15|11|5| Hengshui 16|1|6| Taiyuan 17|2|6| Datong

Enter the following code in the Python console:


>>> Import pandas as PD
>>> df = pd.read_excel (' c:\\users\\thinkpad\\desktop\\data.csv ')
>>> DF

The error is as follows:

In this case, it is the coding problem, only need to specify the encoding at the time of reading.

Solutions

The encoding is specified and the normal read

"Python" read the CVS file error: Unicodedecodeerror: ' Utf-8 ' codec can ' t decode byte 0xb1 in position 6:invalid start byte

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.