LoginSignup
0
1

More than 1 year has passed since last update.

excelでcsvエクスポートし、pandasで読み込む時

Last updated at Posted at 2021-06-23

通常読み込み

通常、csvファイルは以下のコードで読み込みができる。

import pandas as pd

path = "filename"
data = pd.read_csv(path)

しかし、excelからエクスポートしてきたcsvファイルを読み込むと

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x95 in position 0: invalid start byte

上のようなエラーが出る。

解決方法

以下のコードで読み込むことで、解決できます。

import pandas as pd
import codecs


path = "filename"
with codecs.open(path, "r", "Shift-JIS", "ignore") as file:
    data = pd.read_table(file, delimiter=",")
0
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1