How to fix: module ‘pandas’ has no attribute ‘dataframe’

The error message “module ‘pandas’ has no attribute ‘dataframe'” means that the pandas module does not have the dataframe attribute, which is used for creating data frames. To fix this issue, you need to ensure that the pandas module is installed correctly and that the version you are using is up-to-date. You can do this by checking your Python environment and updating your pandas module accordingly. Once the pandas module is up-to-date, you should be able to use the dataframe attribute without any further issues.


One error you may encounter when using pandas is:

AttributeError: module 'pandas' has no attribute 'dataframe'

This error usually occurs for one of three reasons:

1. You write pd.dataframe instead of pd.DataFrame

2. Some other variable is named ‘pd’ or ‘pandas’

3. The file name is pd.py or pandas.py

The following examples show how to resolve this error in each of these scenarios.

Reason 1: Using pd.dataframe

Suppose we attempt to create a pandas DataFrame using the following syntax:

import pandas as pd

#attempt to create DataFrame
df = pd.dataframe({'points': [25, 12, 15, 14],
                   'assists': [5, 7, 13, 12]})

AttributeError: module 'pandas' has no attribute 'dataframe'

We receive an error because we wrote the word dataframe in lowercase.

To create a pandas DataFrame, we must write the word ‘DataFrame’ in camel-case:

import pandas as pd

#create DataFrame
df = pd.DataFrame({'points': [25, 12, 15, 14],
                   'assists': [5, 7, 13, 12]})

#view DataFrame
df

	points	assists
0	25	5
1	12	7
2	15	13
3	14	12

Notice that we’re able to successfully create the DataFrame without any errors.

Reason 2: Some other variable is named ‘pd’ or ‘pandas’

We might also receive this error if some other variable in our script is named ‘pd’ or ‘pandas’:

import pandas as pd

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

#attempt to create DataFrame
df = pd.dataframe({'points': [25, 12, 15, 14],
                   'assists': [5, 7, 13, 12]})

AttributeError: module 'pandas' has no attribute 'dataframe'

import pandas as pd

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

#create DataFrame
df = pd.DataFrame({'points': [25, 12, 15, 14],
                   'assists': [5, 7, 13, 12]})

#view DataFrame
df

	points	assists
0	25	5
1	12	7
2	15	13
3	14	12

Notice that we don’t receive an error because we no longer have a variable named py or pandas.

Reason 3. The file name is pd.py or pandas.py

Another reason you may receive an error is if the file name of your script is pd.py or pandas.py.

To resolve this error, you simply need to rename your file to something else like my_script.py or my_data.py or literally any other name.

The following tutorials explain how to fix other common errors in Python:

x