I am using the Anaconda distribution of Pandas on a Mac.
I am able to use the Pandas module from within the python console, but am unable to use it from within a script file. i.e. when I run a script that imports the pandas module, then I get an attribute error.
For example, this:
import pandas as pd
df = pd.DataFrame()
will give me this error:
Traceback (most recent call last):
File "/Path/To/File/file.py", line 1, in <module>
import pandas as pd
File "/Path/To/File/file.py", line 2, in <module>
df = pd.DataFrame()
AttributeError: 'module' object has no attribute 'DataFrame'
And similarly, this:
import pandas as pd
df = pd.Series()
will give me this error:
Traceback (most recent call last):
File "/Path/To/File/file.py", line 1, in <module>
import pandas as pd
File "/Path/To/File/file.py", line 2, in <module>
sr = pd.Series()
AttributeError: 'module' object has no attribute 'Series'
Yet both of these work fine from the console.
I've tried uninstalling and re-installing from anaconda, pip, and from the github source, to no avail.
Thanks.
is your script named pandas.py?
yikes, yes. (And this now works, thanks.)
To clarify, this was a test file I created after encountering the error in another file where I was getting this:
AttributeError: 'module' object has no attribute 'excel'
And I now realise that this was because the directory in which I had placed the original script also contained a file called 'csv.py', which was evidently causing havoc when Pandas was trying to load internal modules.
Likewise, i had a few spripts with similiar nomenclature of csv.py, csv1.py, etc. I renamed them all and now the scripts are working fine with ipython for that matter.
Most helpful comment
is your script named pandas.py?