Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'module' object has no attribute 'DataFrame' [closed]

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?

like image 893
aerijman Avatar asked Dec 16 '13 21:12

aerijman


People also ask

How do you fix pandas has no attribute DataFrame?

If you have named the script as pd.py or pandas.py then you will get module 'pandas' has no attribute 'dataframe' error. This mainly happens because the file name will shadow the Pandas module and, it can mess up the module imports. We can fix this issue by renaming the script to some other name such as “my_script.py”.

How do I fix pandas attribute error?

The most likely cause of the error is having a local file named pandas.py which shadows the official pandas module. Make sure you haven't misspelled Series as class names are case-sensitive. Make sure to rename your local file to something other than pandas.py to solve the error.

What is attribute error in Jupyter notebook?

AttributeError can be defined as an error that is raised when an attribute reference or assignment fails. For example, if we take a variable x we are assigned a value of 10. In this process suppose we want to append another value to that variable. It's not possible.

How do you append DataFrames in Python?

Series append syntax The syntax for using append on a Series is very similar to the dataframe syntax. You type the name of the first Series, and then . append() to call the method. Then inside the parenthesis, you type the name of the second Series, which you want to append to the end of the first.


2 Answers

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.

like image 194
Daniel Klaus Avatar answered Sep 19 '22 20:09

Daniel Klaus


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.

like image 38
Michael G. Avatar answered Sep 18 '22 20:09

Michael G.