How to Resolve "AtributeError: module 'pandas' has no attribute 'dataframe'" in Python
When starting out with Pandas, one of the most common errors you'll encounter is AttributeError: module 'pandas' has no attribute 'dataframe'. This error trips up many beginners because it's caused by a simple but easy-to-miss capitalization mistake.
In this guide, we'll explain why this error occurs, show you the correct syntax, and cover other similar attribute errors in Pandas that stem from the same issue.
Why Does This Error Occur?
Python is a case-sensitive language, meaning dataframe, DataFrame, and DATAFRAME are all treated as completely different names. The Pandas library defines its DataFrame class as DataFrame (with a capital "D" and capital "F"), not dataframe.
❌ Wrong: Lowercase dataframe:
import pandas as pd
data = {"id": [1, 2, 3], "name": ["Alice", "Bob", "Carol"]}
df = pd.dataframe(data)
print(df)
Output:
AttributeError: module 'pandas' has no attribute 'dataframe'
Python looks for an attribute called dataframe on the pandas module, can't find it, and raises the error.
✅ Correct: Capitalized DataFrame:
import pandas as pd
data = {"id": [1, 2, 3], "name": ["Alice", "Bob", "Carol"]}
df = pd.DataFrame(data)
print(df)
Output:
id name
0 1 Alice
1 2 Bob
2 3 Carol
The naming follows PascalCase convention (also called UpperCamelCase), which is the standard Python naming convention for classes: DataFrame, Series, Timestamp, etc.
Common Variations of This Mistake
The same type of error occurs with other case-sensitive Pandas names. Here are the most frequently misspelled ones:
| ❌ Wrong | ✅ Correct | What It Is |
|---|---|---|
pd.dataframe() | pd.DataFrame() | Create a DataFrame |
pd.series() | pd.Series() | Create a Series |
pd.read_CSV() | pd.read_csv() | Read a CSV file |
pd.Read_csv() | pd.read_csv() | Read a CSV file |
pd.Dataframe() | pd.DataFrame() | Create a DataFrame |
df.Groupby() | df.groupby() | Group data |
df.Merge() | df.merge() | Merge DataFrames |
pd.to_Datetime() | pd.to_datetime() | Convert to datetime |
Notice the pattern:
- Classes use PascalCase:
DataFrame,Series,Timestamp - Functions/methods use snake_case:
read_csv,to_datetime,groupby
Other Causes of This Error
While capitalization is the most common cause, there are a few other situations that can produce the same error message.
A File Named pandas.py in Your Project
If you have a file named pandas.py in your project directory, Python will import your file instead of the actual Pandas library:
❌ Problem: File named pandas.py in the same directory:
my_project/
├── pandas.py ← This shadows the real pandas!
└── analysis.py
# analysis.py
import pandas as pd # This imports YOUR pandas.py, not the library
df = pd.DataFrame({"a": [1, 2, 3]}) # AttributeError!
✅ Fix: Rename your file to something else:
my_project/
├── data_utils.py ← Renamed
└── analysis.py
Also delete any pandas.pyc or __pycache__/pandas.cpython-*.pyc files that may have been cached.
Never name your Python files after standard library modules or popular packages: avoid pandas.py, numpy.py, random.py, collections.py, etc.
Outdated or Corrupted Pandas Installation
In rare cases, a broken installation can cause attribute errors:
# Reinstall pandas
pip uninstall pandas -y
pip install pandas
# Verify the installation
python -c "import pandas as pd; print(pd.__version__); print(pd.DataFrame({'test': [1]}))"
Quick Debugging Steps
When you see module 'pandas' has no attribute '...', check these items:
import pandas as pd
# 1. Check Pandas version (confirms the real pandas is imported)
print(pd.__version__)
# 2. Check the file location (should NOT be your own file)
print(pd.__file__)
# 3. Verify DataFrame is available
print(type(pd.DataFrame))
Expected output:
2.3.3
/usr/local/venv/lib/python3.11/site-packages/pandas/__init__.py
<class 'type'>
If pd.__file__ points to a file in your project directory, you have a naming conflict.
Common DataFrame Creation Examples
Here are correctly written examples for the most common ways to create a DataFrame:
From a Dictionary
import pandas as pd
data = {"name": ["Alice", "Bob"], "age": [30, 25]}
df = pd.DataFrame(data)
print(df)
Output:
name age
0 Alice 30
1 Bob 25
From a List of Dictionaries
import pandas as pd
records = [
{"name": "Alice", "age": 30},
{"name": "Bob", "age": 25}
]
df = pd.DataFrame(records)
print(df)
Output:
name age
0 Alice 30
1 Bob 25
From a List of Lists
import pandas as pd
data = [["Alice", 30], ["Bob", 25]]
df = pd.DataFrame(data, columns=["name", "age"])
print(df)
Output:
name age
0 Alice 30
1 Bob 25
From a CSV File
import pandas as pd
df = pd.read_csv("data.csv") # Note: read_csv, not Read_CSV or read_CSV
print(df)
Conclusion
The AttributeError: module 'pandas' has no attribute 'dataframe' error is almost always caused by a capitalization mistake, writing pd.dataframe() instead of pd.DataFrame().
Python is case-sensitive, and Pandas class names follow PascalCase convention. If the capitalization is correct but the error persists, check that you don't have a file named pandas.py in your project directory that's shadowing the real library. A quick check with pd.__file__ will confirm whether you're importing the correct module.