개발로그필름
[데이터 TIL] pandas에서 CSV 파일을 읽을 때 한글 인코딩 문제 해결 본문
728x90
반응형
SMALL
pandas에서 CSV 파일을 읽을 때 한글 인코딩 문제를 해결하려면
encoding='utf-8' 또는 encoding='cp949'을 추가해야 한다.
✅ 한글이 포함된 CSV 파일을 읽을 때
import pandas as pd
# UTF-8 인코딩으로 읽기
health_df = pd.read_csv(file_path, encoding='utf-8')
# 만약 utf-8에서 오류가 나면 cp949(윈도우 기본 인코딩) 사용
health_df = pd.read_csv(file_path, encoding='cp949')
# 또는 euc-kr(한글 완성형 인코딩) 사용
health_df = pd.read_csv(file_path, encoding='euc-kr')
반응형
📌 인코딩 관련 에러 해결
• UnicodeDecodeError: 'utf-8' codec can't decode → encoding='cp949' 또는 encoding='euc-kr'로 변경
• UnicodeDecodeError: 'cp949' codec can't decode → encoding='utf-8'로 변경
나는 주로 encoding='euc-kr' 를 이용하게 되는 것 같다!
반응형
LIST
'데이터분석가 > 데이터 TIL' 카테고리의 다른 글
[데이터 TIL] 수치형 데이터와 범주형 데이터의 차이 (0) | 2025.02.07 |
---|---|
[데이터 TIL] 칼럼별 결측치 비율 확인하기 (0) | 2025.02.06 |
[데이터 TIL] to_datetime() vs to_timedelta() 차이점 (0) | 2025.02.06 |
TransactionEncoder를 사용한 변환 (0) | 2025.02.05 |
df.groupby("id")["product"].apply(list).tolist() (0) | 2025.02.04 |
Comments