DEV Community

Insung Hwang
Insung Hwang

Posted on

[pandas] 공공데이터(csv) 활용시 한글 깨짐 현상 해결

국토교통부 공공 데이터를 가져와 윈도우에서 파일을 열면 한글이 깨지는 현상이 있습니다. 엑셀로 열면 알아서 변환되어 잘 보이지만, vscode 나 python 으로 열면 한글이 깨지네요.

다세대 전세 실거래가 공공데이터

import pandas as pd

inputfile_path = "input_file.csv"
outputfile_path = "output_file.csv"

file = open(inputfile_path).read()

with open(inputfile_path, "r") as infile:
    content = infile.read()

with open(outputfile_path, "w", encoding="utf-8") as outfile:
    outfile.write(content)


# 15줄까지는 머리말이라 skip
df = pd.read_csv(outputfile_path, skiprows=15)
df.describe()
Enter fullscreen mode Exit fullscreen mode

file write 시 utf-8 인코딩 처리해주니 잘 되네요.

Top comments (0)