Coding Ref

How to fix: AttributeError module 'pandas' has no attribute 'dataframe'

How to fix: AttributeError module 'pandas' has no attribute 'dataframe'

The error AttributeError: module 'pandas' has no attribute 'dataframe' is raised when you try to use the pandas.dataframe class, but this class does not exist in the Pandas library.

In Pandas, the class for creating and manipulating dataframes is called DataFrame, with a capital D and F.

To fix this error, you need to change any instances of pandas.dataframe to pandas.DataFrame in your code.

For example, if you have the following code:

main.py
import pandas as pd

# create a dataframe
df = pd.dataframe({"A": [1, 2, 3], "B": [4, 5, 6]})

# display the dataframe
print(df)
output
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[53], line 4
      1 import pandas as pd
      3 # create a dataframe
----> 4 df = pd.dataframe({"A": [1, 2, 3], "B": [4, 5, 6]})
      6 # display the dataframe
      7 print(df)

File /lib/python3.10/site-packages/pandas/__init__.py:261, in __getattr__(name)
    257     from pandas.core.arrays.sparse import SparseArray as _SparseArray
    259     return _SparseArray
--> 261 raise AttributeError(f"module 'pandas' has no attribute '{name}'")

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

This code will raise the AttributeError: module 'pandas' has no attribute 'dataframe' error, because the dataframe class does not exist in the Pandas library.

To fix this error, you need to change pandas.dataframe to pandas.DataFrame, like this:

main.py
import pandas as pd

# create a dataframe
df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})

# display the dataframe
print(df)
output
   A  B
0  1  4
1  2  5
2  3  6

This code will now create a dataframe using the DataFrame class, and it will not raise the AttributeError error.

Conclusion

The AttributeError: module 'pandas' has no attribute 'dataframe' error is raised when you try to use the pandas.dataframe class, which does not exist in the Pandas library.

To fix this error, you need to change pandas.dataframe to pandas.DataFrame in your code.

You'll also like

Related tutorials curated for you

    How to get the first row in Pandas

    How to normalize a column in Pandas

    How to create a bar chart in Pandas

    How to use str.contains() in Pandas

    How to read a TSV file in Pandas

    What does factorize() do in Pandas?

    How to use astype() in Pandas

    How to use applymap() in Pandas

    How to use nunique() in Pandas

    How to get the number of columns in a Pandas DataFrame

    How to fix: ValueError: pandas cannot reindex from a duplicate axis

    How to give multiple conditions in loc() in Pandas