Fix for AttributeError module pandas has no attribute dataframe

In this section we have discussed the fix for attributeerror module pandas has no attribute dataframe.  The error “AttributeError: module ‘pandas’ has no attribute ‘dataframe’”. Usually occurs for one of these two reasons

Reason1: You write pd.dataframe instead of pd.DataFrame

Reason2:  Some other variable is named ‘pd’ or ‘pandas’

 

Reason 1 for AttributeError: module pandas has no attribute dataframe

AttributeError: module ‘pandas’ has no attribute ‘dataframe’ Occurs when invoking dataframe in all lower case.  i.e. pd.dataframe() . ideally it should be in camel-case. i.e. (pd.DataFrame()) cleans up the problem.

Example :

 

import pandas as pd

#attempt to create DataFrame

df = pd.dataframe({'Maths': [85, 72, 89, 94],
'Science': [95, 77, 73, 92]})

 

Fix-for-AttributeError-module-pandas-has-no-attribute-dataframe-1

 

Fix for AttributeError module pandas has no attribute dataframe

invoking dataframe in all lower case.  i.e. pd.dataframe() . ideally it should be in camel-case. i.e. (pd.DataFrame()) which will fix the above error as shown below.

 

##### Solution
import pandas as pd

#attempt to create DataFrame

df = pd.DataFrame({'Maths': [85, 72, 89, 94],
'Science': [95, 77, 73, 92]})

df

So the dataframe is now created without any error.

Fix-for-AttributeError-module-pandas-has-no-attribute-dataframe-2

 

 

 

Reason2:  Some other variable is named ‘pd’ or ‘pandas’

 

######## Reason 2
import pandas as pd

#create a list named 'pd'
pd = [1, 2, 3, 4]

#attempt to create DataFrame
df = pd.dataframe({'Maths': [85, 72, 89, 94],
'Science': [95, 77, 73, 92]})

df

as the list named pd is created it will give the below error

Error:

Fix-for-AttributeError-module-pandas-has-no-attribute-dataframe-3

Fix :

 

##### Solution
import pandas as pd

##pd is no more a variable
pd1 = [1, 2, 3, 4]

#attempt to create DataFrame

df = pd.DataFrame({'Maths': [85, 72, 89, 94],
'Science': [95, 77, 73, 92]})

df

So the dataframe is now created without any error.

Fix-for-AttributeError-module-pandas-has-no-attribute-dataframe-2

 

 

Author

  • Sridhar Venkatachalam

    With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.

    View all posts