Skip to main content
Communityユーザーがトップに表示した
Communityユーザーがトップに表示した
Communityユーザーがトップに表示した
タイトルと本文の改善
ソース リンク
cubick
  • 2.1万
  • 5
  • 27
  • 64

csvを読み込む PandasでCSVファイルの読み込みに失敗してしまう

macでpythonからcsvを読み込む場合はどのように設定すれば良いでしょうか?
下記のようなコード作成しましたが、実行するとエラーが表示されます。

codeコード

errorエラーメッセージ

csvを読み込む

macでpythonからcsvを読み込む場合はどのように設定すれば良いでしょうか?
下記のようなコード作成しましたが、エラーが表示されます。

code

error

PandasでCSVファイルの読み込みに失敗してしまう

macでpythonからcsvを読み込む場合はどのように設定すれば良いでしょうか?
下記のようなコード作成しましたが、実行するとエラーが表示されます。

コード

エラーメッセージ

本文に 18 文字追加
ソース リンク
htb
  • 2,027
  • 3
  • 15
  • 35

code
import pandas as pd #pandasをpdとしてインポート

df = pd.read_csv("/Users/ha/Desktop/tati.csv", encoding="utf-8_sig")

print (df)

import pandas as pd #pandasをpdとしてインポート

df = pd.read_csv("/Users/ha/Desktop/tati.csv", encoding="utf-8_sig")

print (df)

error

Traceback (most recent call last):
File "casa.py", line 3, in
df = pd.read_csv("/Users/ha/Desktop/tati.csv", encoding="utf-8_sig")
File "/usr/local/lib/python3.7/site-packages/pandas/io/parsers.py", line 702, in parser_f
return _read(filepath_or_buffer, kwds)
File "/usr/local/lib/python3.7/site-packages/pandas/io/parsers.py", line 435, in _read
data = parser.read(nrows)

File "/usr/local/lib/python3.7/site-packages/pandas/io/parsers.py", line 1139, in read
ret = self._engine.read(nrows)
File "/usr/local/lib/python3.7/site-packages/pandas/io/parsers.py", line 1995, in read
data = self._reader.read(nrows)
File "pandas/_libs/parsers.pyx", line 899, in pandas._libs.parsers.TextReader.read
File "pandas/_libs/parsers.pyx", line 914, in pandas._libs.parsers.TextReader._read_low_memory
File "pandas/_libs/parsers.pyx", line 991, in pandas._libs.parsers.TextReader._read_rows
File "pandas/_libs/parsers.pyx", line 1123, in pandas._libs.parsers.TextReader._convert_column_data
File "pandas/_libs/parsers.pyx", line 1176, in pandas._libs.parsers.TextReader._convert_tokens
File "pandas/_libs/parsers.pyx", line 1299, in pandas._libs.parsers.TextReader._convert_with_dtype
File "pandas/_libs/parsers.pyx", line 1318, in pandas._libs.parsers.TextReader._string_convert
File "pandas/_libs/parsers.pyx", line 1611, in pandas._libs.parsers._string_box_decode
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/encodings/utf_8_sig.py", line 23, in de
code
(output, consumed) = codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8a in position 0: invalid start byte

Traceback (most recent call last):
  File "casa.py", line 3, in <module>
    df = pd.read_csv("/Users/ha/Desktop/tati.csv", encoding="utf-8_sig")
  File "/usr/local/lib/python3.7/site-packages/pandas/io/parsers.py", line 702, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "/usr/local/lib/python3.7/site-packages/pandas/io/parsers.py", line 435, in _read
    data = parser.read(nrows)

  File "/usr/local/lib/python3.7/site-packages/pandas/io/parsers.py", line 1139, in read
    ret = self._engine.read(nrows)
  File "/usr/local/lib/python3.7/site-packages/pandas/io/parsers.py", line 1995, in read
    data = self._reader.read(nrows)
  File "pandas/_libs/parsers.pyx", line 899, in pandas._libs.parsers.TextReader.read
  File "pandas/_libs/parsers.pyx", line 914, in pandas._libs.parsers.TextReader._read_low_memory
  File "pandas/_libs/parsers.pyx", line 991, in pandas._libs.parsers.TextReader._read_rows
  File "pandas/_libs/parsers.pyx", line 1123, in pandas._libs.parsers.TextReader._convert_column_data
  File "pandas/_libs/parsers.pyx", line 1176, in pandas._libs.parsers.TextReader._convert_tokens
  File "pandas/_libs/parsers.pyx", line 1299, in pandas._libs.parsers.TextReader._convert_with_dtype
  File "pandas/_libs/parsers.pyx", line 1318, in pandas._libs.parsers.TextReader._string_convert
  File "pandas/_libs/parsers.pyx", line 1611, in pandas._libs.parsers._string_box_decode
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/encodings/utf_8_sig.py", line 23, in de
code
    (output, consumed) = codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8a in position 0: invalid start byte

code
import pandas as pd #pandasをpdとしてインポート

df = pd.read_csv("/Users/ha/Desktop/tati.csv", encoding="utf-8_sig")

print (df)

error

Traceback (most recent call last):
File "casa.py", line 3, in
df = pd.read_csv("/Users/ha/Desktop/tati.csv", encoding="utf-8_sig")
File "/usr/local/lib/python3.7/site-packages/pandas/io/parsers.py", line 702, in parser_f
return _read(filepath_or_buffer, kwds)
File "/usr/local/lib/python3.7/site-packages/pandas/io/parsers.py", line 435, in _read
data = parser.read(nrows)

File "/usr/local/lib/python3.7/site-packages/pandas/io/parsers.py", line 1139, in read
ret = self._engine.read(nrows)
File "/usr/local/lib/python3.7/site-packages/pandas/io/parsers.py", line 1995, in read
data = self._reader.read(nrows)
File "pandas/_libs/parsers.pyx", line 899, in pandas._libs.parsers.TextReader.read
File "pandas/_libs/parsers.pyx", line 914, in pandas._libs.parsers.TextReader._read_low_memory
File "pandas/_libs/parsers.pyx", line 991, in pandas._libs.parsers.TextReader._read_rows
File "pandas/_libs/parsers.pyx", line 1123, in pandas._libs.parsers.TextReader._convert_column_data
File "pandas/_libs/parsers.pyx", line 1176, in pandas._libs.parsers.TextReader._convert_tokens
File "pandas/_libs/parsers.pyx", line 1299, in pandas._libs.parsers.TextReader._convert_with_dtype
File "pandas/_libs/parsers.pyx", line 1318, in pandas._libs.parsers.TextReader._string_convert
File "pandas/_libs/parsers.pyx", line 1611, in pandas._libs.parsers._string_box_decode
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/encodings/utf_8_sig.py", line 23, in de
code
(output, consumed) = codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8a in position 0: invalid start byte

code

import pandas as pd #pandasをpdとしてインポート

df = pd.read_csv("/Users/ha/Desktop/tati.csv", encoding="utf-8_sig")

print (df)

error

Traceback (most recent call last):
  File "casa.py", line 3, in <module>
    df = pd.read_csv("/Users/ha/Desktop/tati.csv", encoding="utf-8_sig")
  File "/usr/local/lib/python3.7/site-packages/pandas/io/parsers.py", line 702, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "/usr/local/lib/python3.7/site-packages/pandas/io/parsers.py", line 435, in _read
    data = parser.read(nrows)

  File "/usr/local/lib/python3.7/site-packages/pandas/io/parsers.py", line 1139, in read
    ret = self._engine.read(nrows)
  File "/usr/local/lib/python3.7/site-packages/pandas/io/parsers.py", line 1995, in read
    data = self._reader.read(nrows)
  File "pandas/_libs/parsers.pyx", line 899, in pandas._libs.parsers.TextReader.read
  File "pandas/_libs/parsers.pyx", line 914, in pandas._libs.parsers.TextReader._read_low_memory
  File "pandas/_libs/parsers.pyx", line 991, in pandas._libs.parsers.TextReader._read_rows
  File "pandas/_libs/parsers.pyx", line 1123, in pandas._libs.parsers.TextReader._convert_column_data
  File "pandas/_libs/parsers.pyx", line 1176, in pandas._libs.parsers.TextReader._convert_tokens
  File "pandas/_libs/parsers.pyx", line 1299, in pandas._libs.parsers.TextReader._convert_with_dtype
  File "pandas/_libs/parsers.pyx", line 1318, in pandas._libs.parsers.TextReader._string_convert
  File "pandas/_libs/parsers.pyx", line 1611, in pandas._libs.parsers._string_box_decode
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/encodings/utf_8_sig.py", line 23, in de
code
    (output, consumed) = codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8a in position 0: invalid start byte
ソース リンク
幸589
  • 455
  • 2
  • 16
  • 51

csvを読み込む

macでpythonからcsvを読み込む場合はどのように設定すれば良いでしょうか?
下記のようなコード作成しましたが、エラーが表示されます。

code
import pandas as pd #pandasをpdとしてインポート

df = pd.read_csv("/Users/ha/Desktop/tati.csv", encoding="utf-8_sig")

print (df)

error

Traceback (most recent call last):
File "casa.py", line 3, in
df = pd.read_csv("/Users/ha/Desktop/tati.csv", encoding="utf-8_sig")
File "/usr/local/lib/python3.7/site-packages/pandas/io/parsers.py", line 702, in parser_f
return _read(filepath_or_buffer, kwds)
File "/usr/local/lib/python3.7/site-packages/pandas/io/parsers.py", line 435, in _read
data = parser.read(nrows)

File "/usr/local/lib/python3.7/site-packages/pandas/io/parsers.py", line 1139, in read
ret = self._engine.read(nrows)
File "/usr/local/lib/python3.7/site-packages/pandas/io/parsers.py", line 1995, in read
data = self._reader.read(nrows)
File "pandas/_libs/parsers.pyx", line 899, in pandas._libs.parsers.TextReader.read
File "pandas/_libs/parsers.pyx", line 914, in pandas._libs.parsers.TextReader._read_low_memory
File "pandas/_libs/parsers.pyx", line 991, in pandas._libs.parsers.TextReader._read_rows
File "pandas/_libs/parsers.pyx", line 1123, in pandas._libs.parsers.TextReader._convert_column_data
File "pandas/_libs/parsers.pyx", line 1176, in pandas._libs.parsers.TextReader._convert_tokens
File "pandas/_libs/parsers.pyx", line 1299, in pandas._libs.parsers.TextReader._convert_with_dtype
File "pandas/_libs/parsers.pyx", line 1318, in pandas._libs.parsers.TextReader._string_convert
File "pandas/_libs/parsers.pyx", line 1611, in pandas._libs.parsers._string_box_decode
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/encodings/utf_8_sig.py", line 23, in de
code
(output, consumed) = codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8a in position 0: invalid start byte