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.

AttributeError: module 'pandas.io.common' has no attribute 'EmptyDataError'

Posted at

read_csvで空のcsvを読むときにエラーが生じてしまうため、csvが空のときエラーを返す処理を入れた。

python
l=14 # number of files
for i in range(len(l)):
    try:
        file_name="./"+str(l)+"_test.csv"
    except EmptyDataError:
        print("ERROR: {} is empty".format(i))

しかし、
下記のエラーメッセージが出る。

EmptyDataError: No columns to parse from file

During handling of the above exception, another exception occurred:

NameError                                 Traceback (most recent call last)
<ipython-input-5-15b8cfd9c905> in <module>
      7 
      8         #print(tmp_df)
----> 9     except EmptyDataError:
     10         print("ERROR: {} is empty".format(i))
     11         next

NameError: name 'EmptyDataError' is not defined

AttributeError: module 'pandas.io.common' has no attribute 'EmptyDataError'
その対処法を調べたところ、pandas 1.1.5辺りから
参照先が変わったらしい。
https://ameblo.jp/altair265/entry-12644270493.html

from pandas.errors import EmptyDataError
の一文を入れて実行したら、エラーはでず、問題解決した。

python
from pandas.errors import EmptyDataError
l=14 # number of files
for i in range(len(l)):
    try:
        file_name="./"+str(l)+"_test.csv"
    except EmptyDataError:
        print("ERROR: {} is empty".format(i))

ERROR: 8 is empty
ERROR: 10 is empty
     max  width  n.sample  
0         0.439           -1.04     500.0   
1         0.490           -0.96     500.0   
2         0.439           -0.96     500.0   
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?