Skip to content

Commit 29e3726

Browse files
committed
decode Error post
1 parent 6d285bc commit 29e3726

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

_posts/2024-10-04-error_decode.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: "[Error] 파일 로드 시 발생하는 Decode 오류 해결 방법"
3+
excerpt: "Solution for decode error by Junhyuns"
4+
5+
categories:
6+
- Python
7+
tags:
8+
- [Python, decode error, UnicodeDecodeError, pandas, csv]
9+
10+
toc: true
11+
toc_sticky: true
12+
13+
date: 2024-10-04
14+
last_modified_at: 2024-10-04
15+
16+
math: true
17+
---
18+
19+
Pandas를 활용해서 csv 파일을 불러올 때 발생할 수 있는 에러에 대한 해결 방안입니다.
20+
21+
다음과 같이 pd.read_csv() 함수를 통해 csv 파일을 불러올 때 가끔 아래와 같은 애러가 발생합니다.
22+
23+
```python
24+
data = pd.read_csv(PATH)
25+
26+
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x90 in position 80: invalid start byte
27+
```
28+
29+
Pandas에서는 별도의 encoding argument를 주지 않는 경우 "utf-8"을 이용해서 디코딩을 진행하는데, 해당 파일이 "utf-8"로 인코딩된 파일이 아닌 경우 발생하는 오류입니다.
30+
31+
아래와 같이 pd.read_csv() 함수에 encoding argument를 넣어줌으로써 해결할 수 있습니다.
32+
33+
```python
34+
data = pd.read_csv(PATH, encoding="cp949")
35+
```
36+
37+
또는
38+
39+
```python
40+
data = pd.read_csv(PATH, encoding="utf-8-sig")
41+
```

0 commit comments

Comments
 (0)