0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【初心者】pandasのcsv読み込みで”[Errno 2] File b'test.csv' does not exist: b'test.csv”が表示された時の対処

Posted at

環境

Python 3.6.5
pandas 0.25.3

概要

pandas.read_csv()で、カンマ区切りのcsvファイルの読み込む

発生した課題

FileNotFoundError: [Errno 2] File b'test.csv' does not exist: b'test.csv'
訳:b’test.csv’が見つかりません!

※本来のファイル名は’test.csv’なのですが、なぜbがファイル名の先頭についているかという疑問はこの際置いといて・・・

データ

test.csv

   名前  国語  数学  英語  理科  社会
0  A太   83  89  76  97  76
1  B介   66  93  75  88  76
2  C子  100  84  96  82  94
3  D郎   60  73  63  52  70
4  E美   92  62  84  80  78
5  F菜   96  92  94  92  90

ソースコード

import pandas as pd
df = pd.read_csv("test.csv")

print(df)

とりあえずまずはcsv読み込んで、コンソールで確認できるか?という初手の確認を行おうとしたときのエラーでした。

解決法

下記コードを追加して、カレントディレクトリを指定すると問題なく読み込めました。
スクリプトもcsvも同じ階層に置いてたのになんでだろう・・

import os

# カレントディレクトリを指定
path = “csvが保存されているディレクトリ”
os.chdir(path)
0
0
0

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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?