› Forums › Python › Pandas (Python library) › Understanding describe() in Pandas: A Beginner-Friendly Guide
- This topic is empty.
-
AuthorPosts
-
February 19, 2026 at 10:39 am #6110
When working with data in Python using Pandas, one of the first things you usually want to know is:
❓ What does my data look like? What are the averages, minimums, and maximums?
Pandas provides a powerful method called
describe()that helps you answer these questions instantly.In this tutorial, you’ll learn:
- What
describe()does - Why
pd.describe()does not work - How to correctly use
describe() - Common beginner mistakes
- Practical examples
✅ 1. Setting Up the Context
Imagine you are working with a dataset that contains real estate information, such as:
- Property area in square meters (
area_m2) - Property price in US dollars (
price_usd)
Let’s start by importing Pandas and creating a sample DataFrame.
Initial Code
import pandas as pd # Create sample data data = { "area_m2": [60, 75, 90, 120, 150], "price_usd": [70000, 95000, 120000, 170000, 230000] } # Create DataFrame df = pd.DataFrame(data) # View data print(df)Output
area_m2 price_usd 0 60 70000 1 75 95000 2 90 120000 3 120 170000 4 150 230000Now we have real data to work with.
❌ 2. A Common Beginner Mistake
Many beginners try something like this:
stats = pd.describe(["area_m2"], ["price_usd"])This does not work.
Why?
Because:
describe()is not a function insidepd- You passed column names as strings, not actual data
describe()works on DataFrames or Series
So Pandas cannot calculate statistics from this.
✅ 3. The Correct Way to Use
describe()In Pandas,
describe()is a method of a DataFrame.That means:
You must call it on
df, not onpd.Correct Code
stats = df[["area_m2", "price_usd"]].describe() print(stats)
📊 4. Understanding the Output
You will get something like:
area_m2 price_usd count 5.0000 5.0000 mean 99.0000 137000.0000 std 35.4965 63529.9600 min 60.0000 70000.0000 25% 75.0000 95000.0000 50% 90.0000 120000.0000 75% 120.0000 170000.0000 max 150.0000 230000.0000Let’s understand what each row means:
Statistic Meaning count Number of values mean Average std Standard deviation min Smallest value 25% First quartile 50% Median 75% Third quartile max Largest value These give you a quick summary of your dataset.
✅ 5. Describing a Single Column
If you want statistics for only one column:
For
area_m2area_stats = df["area_m2"].describe() print(area_stats)For
price_usdprice_stats = df["price_usd"].describe() print(price_stats)This returns statistics for just that column.
✅ 6. Describing All Numeric Columns
If your dataset has many columns, you can simply write:
stats = df.describe() print(stats)Pandas will automatically:
- Select numeric columns
- Ignore text columns
- Summarize useful statistics
This is very helpful in real-world projects.
⚠️ 7. Why Passing Column Names Does Not Work
Look at this incorrect example:
df.describe(["area_m2", "price_usd"])This does not work because:
"area_m2"is just text- Pandas needs actual values
- Not column labels
Think like this:
❌ Column names = labels
✅ Column data = numbersdescribe()works only with numbers.
💡 8. The Pattern You Should Remember
Always remember this structure:
For multiple columns:
df[["col1", "col2"]].describe()For one column:
df["col1"].describe()For whole DataFrame:
df.describe()If you remember this pattern, you’ll avoid most mistakes.
🌟 9. Real-World Use Case
In real projects,
describe()is often used:- Before cleaning data
- Before building ML models
- While exploring datasets
- To detect outliers
- To check data quality
Example:
# Check dataset before analysis print(df.describe())This helps you understand your data in seconds.
📌 10. Summary
Let’s summarize what we learned.
❌ Wrong Way
pd.describe(["area_m2"], ["price_usd"])✅ Correct Ways
# Multiple columns df[["area_m2", "price_usd"]].describe() # Single column df["area_m2"].describe() # Entire DataFrame df.describe()
✅ Key Takeaways
✔
describe()is a DataFrame method
✔ It summarizes numeric data
✔ It does not work on column names
✔ It helps in quick data exploration
- What
-
AuthorPosts
- You must be logged in to reply to this topic.
