1
votes

My code is simply the follow and work few days ago:

import pandas as pd

df = pd.read_csv('WORLDBANK-ZAF_MYS_PROP_4044_SEC_MF.csv')
print(df.head())

But now whenever I try to run it by calling python my_io.py on my Mac terminal it generates the following messages:

Bases-MacBook-Pro:data_analysis me$ python my_io.py Traceback (most recent call last): File "my_io.py", line 1, in import pandas as pd File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/init.py", line 13, in import(dependency) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/init.py", line 142, in from . import add_newdocs File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in from numpy.lib import add_newdoc File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/init.py", line 8, in from .type_check import * File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in import numpy.core.numeric as _nx File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/init.py", line 72, in from numpy.testing.nosetester import _numpy_tester File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/testing/init.py", line 12, in from . import decorators as dec File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/testing/decorators.py", line 20, in from .utils import SkipTest, assert_warns File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/testing/utils.py", line 15, in from tempfile import mkdtemp, mkstemp File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in import io as _io File "/Users/gongzhuli/Desktop/data_analysis/io.py", line 3, in

AttributeError: 'module' object has no attribute 'read_csv'

Can someone please help me, I have no idea what is going on here..

1

1 Answers

1
votes

Your file is called io.py, which is a library module to handle file-like buffers among other things.

pandas imports tempfile which needs it:

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in <module>
    import io as _io

and your filename gets in the way of the import chain and prevents import from going through.

Just rename your file with something more specific (like my_io.py for instance?)