[ Code ]
---------------------------------------------------------------------------
import pandas as pd
df1 = pd.read_csv('sample.csv')
---------------------------------------------------------------------------
[ Error message ]
C:\py_test> python sample.py
Traceback (most recent call last):
File "C:\py_test\sample.py", line 3, in <module>
df1 = pd.read_csv('sample.csv')
File "C:\Python\Python39\lib\site-packages\pandas\util\_decorators.py", line 311, in wrapper
return func(*args, **kwargs)
File "C:\Python\Python39\lib\site-packages\pandas\io\parsers\readers.py", line 680, in read_csv
return _read(filepath_or_buffer, kwds)
File "C:\Python\Python39\lib\site-packages\pandas\io\parsers\readers.py", line 575, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "C:\Python\Python39\lib\site-packages\pandas\io\parsers\readers.py", line 933, in __init__
self._engine = self._make_engine(f, self.engine)
File "C:\Python\Python39\lib\site-packages\pandas\io\parsers\readers.py", line 1235, in _make_engine
return mapping[engine](f, **self.options)
File "C:\Python\Python39\lib\site-packages\pandas\io\parsers\c_parser_wrapper.py", line 75, in __init__
self._reader = parsers.TextReader(src, **kwds)
File "pandas\_libs\parsers.pyx", line 544, in pandas._libs.parsers.TextReader.__cinit__
File "pandas\_libs\parsers.pyx", line 633, in pandas._libs.parsers.TextReader._get_header
File "pandas\_libs\parsers.pyx", line 847, in pandas._libs.parsers.TextReader._tokenize_rows
File "pandas\_libs\parsers.pyx", line 1952, in pandas._libs.parsers.raise_parser_error
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc7 in position 0: invalid continuation byte
[ solve ]
pandas read_csv encoding add (encoding='cp949')
---------------------------------------------------------------------------
import pandas as pd
df1 = pd.read_csv('sample.csv', encoding='cp949')
----------------------------------------------------------------------------
'개발 > Python' 카테고리의 다른 글
구글 코랩 판다스 read_csv 인코딩 오류 (0) | 2024.02.17 |
---|---|
로또 번호 생성기, 로또 6/45 (0) | 2023.12.15 |
천 단위 숫자를 컴마(',')로 구분하기 (0) | 2023.06.11 |
Raspberry Pi - ImportError: libf77blas.so.3: cannot open shared object file: No such file or directory (0) | 2023.05.04 |
Lotto 6/45 (korea lottery) random generation pyscript version(v0.1) (0) | 2023.04.28 |