1

I have a Python 3.6 |Anaconda 4.3.1 (64-bit)| installation. When I import pandas in shell mode in the command window or in IPython, it works fine.

The code I tried to run was pretty simple

import pandas as pd

animals = ['Tiger', 'Bear', 'Moose']
print(pd.Series(animals))

However, when I write the code using notepad++ and call it from the command window (e.g., python text.py), it throws up the following exception:

Traceback (most recent call last):
File "series_intro.py", line 1, in <module> import pandas as pd
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\__init__.py", line 37,
in <module>
import pandas.core.config_init
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\config_init.py",
line 18, in <module>
from pandas.formats.format import detect_console_encoding
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\formats\format.py", li
ne 33, in <module>
from pandas.io.common import _get_handle, UnicodeWriter, _expand_user
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\common.py", line 40
7, in <module>
def UnicodeReader(f, dialect=csv.excel, encoding="utf-8", **kwds):
AttributeError: module 'csv' has no attribute 'excel'

Please help.

Tried a suggestion from a response on this thread and modified the code to

import csv
print(csv.__file__)
import pandas as pd


animals = ['Tiger', 'Bear', 'Moose']
print(pd.Series(animals))

The following traceback error occurs:

C:\Users\k\Dropbox\data science>python panda_intro.py
C:\Users\k\Dropbox\data science\csv.py
Traceback (most recent call last):
  File "panda_intro.py", line 3, in <module>
    import pandas as pd
  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\__init__.py", line 37,
 in <module>
    import pandas.core.config_init
  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\config_init.py",
line 18, in <module>
    from pandas.formats.format import detect_console_encoding
  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\formats\format.py", li
ne 33, in <module>
    from pandas.io.common import _get_handle, UnicodeWriter, _expand_user
  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\common.py", line 40
7, in <module>
    def UnicodeReader(f, dialect=csv.excel, encoding="utf-8", **kwds):
AttributeError: module 'csv' has no attribute 'excel'
DSM
  • 342,061
  • 65
  • 592
  • 494
Kels
  • 11
  • 2
  • Provide your code too, so it is more likely to get help. – M-- Apr 18 '17 at 03:59
  • The code I tried to run was pretty simple import pandas animals = ['Tiger', 'Bear', 'Moose'] print(pd.Series(animals)) – Kels Apr 19 '17 at 05:12
  • Just change this: `Import pandas as pd` – M-- Apr 19 '17 at 13:10
  • sorry the code had that already. Still same traceback – Kels Apr 20 '17 at 14:23
  • Unexpected AttributeErrors are usually the result of shadowing one module with another. Could you add `import csv`, `print(csv.__file__)` before the `import pandas as pd` line and edit your question to include the result? – DSM Apr 20 '17 at 14:48
  • @Kels: I meant include the result of the `print` -- we're trying to find out whether you're importing the right `csv` module. – DSM Apr 23 '17 at 15:10
  • @DSM: I have modified the output to include the result of the `print` – Kels Apr 24 '17 at 16:19

0 Answers0