0
0
Data Analysis Pythondata~5 mins

Descriptive statistics review in Data Analysis Python

Choose your learning style9 modes available
Introduction

Descriptive statistics help us understand data by summarizing it with simple numbers and charts.

You want to know the average score of a class test.
You need to find the most common color of cars in a parking lot.
You want to see how spread out people's heights are in a group.
You want to quickly describe sales numbers for a month.
You want to check if data has any unusual values.
Syntax
Data Analysis Python
import pandas as pd

# Calculate mean, median, mode, std, min, max
mean_value = data['column'].mean()
median_value = data['column'].median()
mode_value = data['column'].mode()[0]
std_dev = data['column'].std()
minimum = data['column'].min()
maximum = data['column'].max()

# Or get all at once
summary = data['column'].describe()

Use describe() to get many stats quickly.

Mode may return multiple values; use the first one with [0].

Examples
Finds the average age in the data.
Data Analysis Python
mean_age = data['age'].mean()
Finds the middle income value when sorted.
Data Analysis Python
median_income = data['income'].median()
Finds the most common color.
Data Analysis Python
mode_color = data['color'].mode()[0]
Gets count, mean, std, min, max, and quartiles for scores.
Data Analysis Python
summary_stats = data['score'].describe()
Sample Program

This code creates a small dataset and calculates basic descriptive statistics like mean, median, mode, and a summary for age.

Data Analysis Python
import pandas as pd

# Create sample data
data = pd.DataFrame({
    'age': [23, 45, 31, 35, 23, 40, 29],
    'income': [50000, 64000, 58000, 60000, 52000, 62000, 58000],
    'color': ['red', 'blue', 'red', 'green', 'blue', 'blue', 'red']
})

# Calculate descriptive statistics
mean_age = data['age'].mean()
median_income = data['income'].median()
mode_color = data['color'].mode()[0]
summary_age = data['age'].describe()

print(f"Mean age: {mean_age}")
print(f"Median income: {median_income}")
print(f"Most common color: {mode_color}")
print("Age summary stats:\n", summary_age)
OutputSuccess
Important Notes

Descriptive statistics give a quick snapshot but do not explain why data looks a certain way.

Always check for missing data before calculating statistics.

Use visualizations alongside stats for better understanding.

Summary

Descriptive statistics summarize data with simple numbers.

Common stats include mean, median, mode, standard deviation, min, and max.

Use describe() in pandas for a quick summary.