반응형
Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 |
Tags
- math
- Kotlin
- Python
- hive
- google apps script
- c#
- Java
- array
- list
- SQL
- PySpark
- numpy
- matplotlib
- Google Excel
- Apache
- Github
- PANDAS
- Excel
- string
- gas
- dataframe
- Redshift
- Tkinter
- GIT
- Mac
- 파이썬
- Google Spreadsheet
- PostgreSQL
- django
Archives
- Today
- Total
달나라 노트
Python Pandas : UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 0: invalid start byte (read_csv 에러, read_csv error, encoding error) 본문
Python/Python Pandas
Python Pandas : UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 0: invalid start byte (read_csv 에러, read_csv error, encoding error)
CosmosProject 2022. 2. 11. 01:49728x90
반응형
간혹 read_csv method로 csv 파일을 읽을 때 아래와 같은 error가 발생하는 경우가 있습니다.
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 0: invalid start byte
encoding관련 문제가 생겨서 발생하는 error인데
이러한 error가 발생하면 먼저 원본 csv 파일에 한글이 섞여있는지 확인해보면 좋습니다.
import pandas as pd
df_test = pd.read_csv('test.csv', sep=',', encoding='euc-kr')
df_test = pd.read_csv('test.csv', sep=',', encoding='cp949')
만약 한글이 포함되어있다면 위처럼 read_csv method의 encoding 옵션에 euc-kr 또는 cp949를 적어주면 해결됩니다.
euc-kr과 cp949는 모두 한글의 encoding 방식입니다.
그런데 cp949가 euc-kr의 확장판과 같은 것이라서 euc-kr이 읽어내지 못하는 것을 cp949는 읽어낼 수 있습니다.
따라서 euc-kr보단 cp949를 사용하는 것을 추천드립니다.
728x90
반응형
'Python > Python Pandas' 카테고리의 다른 글
Comments