'module' object has no attribute 'DataFrame'
Question:
For the following code:
import pandas as pd
df = pd.DataFrame(np.random.rand(12,2), columns=['Apples', 'Oranges'] )
df['Categories'] = pd.Series(list('AAAABBBBCCCC'))
pd.options.display.mpl_style = 'default'
df.boxplot(by='Categories')
I get the error:
'pandas' object has no attribute 'DataFrame'.
Any ideas on what is happening and how to fix this problem?
Answers:
Please check if:
a) you’ve named a file ‘pandas.py’ in the same directory as your script, or
b) another variable called ‘pd’ is used in your program.
The code presented here doesn’t show this discrepancy, but sometimes I get stuck when invoking dataframe
in all lower case.
Switching to camel-case (pd.DataFrame()
) cleans up the problem.
I have faced similar problem, ‘int’ object has no attribute ‘DataFrame’,
This was because i have mistakenly used pd as a variable in my code and assigned an integer to it, while using the same pd as my pandas dataframe object by declaring – import pandas as pd.
I realized this, and changed my variable to something else, and fixed the error.
Please make sure that your file name should not be panda.py
or pd.py
.
Also, make sure that panda is there in your Lib/site-packages
directory, if not that you need to install panda using below command line:
pip install pandas
if you work with proxy then try calling below in command prompt:
python.exe -m pip install pandas --proxy="YOUR_PROXY_IP:PORT"
For me he problem was that my script was called pandas.py
in the folder pandas
which obviously messed up my imports.
Change the file name if your file name is like pandas.py
or pd.py
, as, otherwise, the file name will shadow the real name. In this case, an error message may also be raised, citing a possible circular import.
I recieved a similar error:
AttributeError: module ‘pandas’ has no attribute ‘DataFrame’
The cause of my error was that I ran pip install of pandas as root, and my user did not have permission to the directory.
My fix was to run:
sudo chmod -R 755 /usr/local/lib/python3.6/site-packages
There may be two causes:
-
It is case-sensitive: DataFrame …. Dataframe, dataframe will not work.
-
You have not install pandas (pip install pandas
) in the python path.
For the following code:
import pandas as pd
df = pd.DataFrame(np.random.rand(12,2), columns=['Apples', 'Oranges'] )
df['Categories'] = pd.Series(list('AAAABBBBCCCC'))
pd.options.display.mpl_style = 'default'
df.boxplot(by='Categories')
I get the error:
'pandas' object has no attribute 'DataFrame'.
Any ideas on what is happening and how to fix this problem?
Please check if:
a) you’ve named a file ‘pandas.py’ in the same directory as your script, or
b) another variable called ‘pd’ is used in your program.
The code presented here doesn’t show this discrepancy, but sometimes I get stuck when invoking dataframe
in all lower case.
Switching to camel-case (pd.DataFrame()
) cleans up the problem.
I have faced similar problem, ‘int’ object has no attribute ‘DataFrame’,
This was because i have mistakenly used pd as a variable in my code and assigned an integer to it, while using the same pd as my pandas dataframe object by declaring – import pandas as pd.
I realized this, and changed my variable to something else, and fixed the error.
Please make sure that your file name should not be panda.py
or pd.py
.
Also, make sure that panda is there in your Lib/site-packages
directory, if not that you need to install panda using below command line:
pip install pandas
if you work with proxy then try calling below in command prompt:
python.exe -m pip install pandas --proxy="YOUR_PROXY_IP:PORT"
For me he problem was that my script was called pandas.py
in the folder pandas
which obviously messed up my imports.
Change the file name if your file name is like pandas.py
or pd.py
, as, otherwise, the file name will shadow the real name. In this case, an error message may also be raised, citing a possible circular import.
I recieved a similar error:
AttributeError: module ‘pandas’ has no attribute ‘DataFrame’
The cause of my error was that I ran pip install of pandas as root, and my user did not have permission to the directory.
My fix was to run:
sudo chmod -R 755 /usr/local/lib/python3.6/site-packages
There may be two causes:
-
It is case-sensitive: DataFrame …. Dataframe, dataframe will not work.
-
You have not install pandas (
pip install pandas
) in the python path.