Complete Statistics Notes with Python
1. What is Statistics?
Statistics is the subject used to collect, organize, analyze, interpret, and present data.
In Data Science, statistics helps us answer questions like:
• What is the average sales value?
• Are two groups different from each other?
• Is there a relationship between two columns?
• Can we trust a sample result?
• Is a machine learning model performing well?
Example:
import pandas as pd
sales = [100, 150, 200, 250, 300]
df = [Link]({"sales": sales})
print(df)
2. Types of Statistics
Statistics is mainly divided into two types:
2.1 Descriptive Statistics
Descriptive statistics describes the data that we already have.
Example questions:
• What is the mean?
• What is the median?
• What is the highest value?
• How spread out is the data?
2.2 Inferential Statistics
Inferential statistics uses sample data to make conclusions about a larger population.
1
Example questions:
• Is the average salary of data analysts greater than 40,000?
• Are male and female customers spending differently?
• Is a new website design improving conversion rate?
3. Population and Sample
Population
The full group you want to study.
Example:
All Netflix users in India.
Sample
A smaller part selected from the population.
Example:
1,000 Netflix users selected from India.
Why sample?
Because studying the entire population is usually expensive, slow, or impossible.
import pandas as pd
population = [Link]({
"user_id": range(1, 101),
"watch_hours": range(10, 110)
})
sample = [Link](n=10, random_state=42)
print(sample)
2
4. Types of Data
4.1 Numerical Data
Data represented using numbers.
Examples:
• Age
• Salary
• Price
• Rating
• Sales
Numerical data has two types:
Discrete Data
Countable numbers.
Examples:
• Number of students
• Number of apps
• Number of movies
Continuous Data
Measurable values that can contain decimals.
Examples:
• Height
• Weight
• Temperature
• Price
4.2 Categorical Data
Data represented using categories.
Examples:
• Gender
• City
• Movie genre
3
• App category
• Payment type
Categorical data has two types:
Nominal Data
Categories without order.
Examples:
• Gender
• City
• Genre
Ordinal Data
Categories with order.
Examples:
• Low, Medium, High
• Poor, Average, Good, Excellent
5. Creating a Simple Dataset
import pandas as pd
_data = {
"student": ["A", "B", "C", "D", "E", "F", "G", "H"],
"gender": ["Male", "Female", "Male", "Female", "Male", "Female", "Male",
"Female"],
"study_hours": [2, 4, 3, 5, 6, 7, 4, 8],
"marks": [45, 60, 55, 70, 75, 85, 65, 90],
"passed": ["No", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes"]
}
df = [Link](_data)
print(df)
4
6. Descriptive Statistics
6.1 Mean
Mean means average.
Formula:
Mean = Sum of all values / Number of values
mean_marks = df["marks"].mean()
print(mean_marks)
Use mean when:
• Data is numerical
• Data does not have many extreme outliers
Example:
Average marks of students.
6.2 Median
Median is the middle value after sorting the data.
median_marks = df["marks"].median()
print(median_marks)
Use median when:
• Data has outliers
• You want a more stable center value
Example:
Median salary is usually better than mean salary because some people may have extremely high salaries.
6.3 Mode
Mode is the most repeated value.
5
mode_gender = df["gender"].mode()
print(mode_gender)
Use mode when:
• Data is categorical
• You want the most common category
Example:
Most common app category.
6.4 Minimum and Maximum
print(df["marks"].min())
print(df["marks"].max())
6.5 Range
Range shows the difference between maximum and minimum values.
marks_range = df["marks"].max() - df["marks"].min()
print(marks_range)
Range is simple but sensitive to outliers.
7. Variance and Standard Deviation
7.1 Variance
Variance tells how much values are spread from the mean.
High variance means values are far from the mean.
Low variance means values are close to the mean.
6
variance_marks = df["marks"].var()
print(variance_marks)
7.2 Standard Deviation
Standard deviation is the square root of variance.
It is easier to understand because it is in the same unit as the original data.
std_marks = df["marks"].std()
print(std_marks)
Interpretation:
If average marks are 68 and standard deviation is 15, then marks usually vary around 15 marks from the
average.
8. Percentiles and Quartiles
Percentile
A percentile tells the position of a value in the data.
Example:
If a student is at the 90th percentile, it means the student scored better than 90% of students.
print(df["marks"].quantile(0.25))
print(df["marks"].quantile(0.50))
print(df["marks"].quantile(0.75))
Quartiles
Quartiles divide data into 4 parts.
• Q1 = 25th percentile
• Q2 = 50th percentile = median
• Q3 = 75th percentile
7
9. Interquartile Range IQR
IQR measures the spread of the middle 50% data.
Formula:
IQR = Q3 - Q1
Q1 = df["marks"].quantile(0.25)
Q3 = df["marks"].quantile(0.75)
IQR = Q3 - Q1
print(IQR)
IQR is useful for detecting outliers.
10. Outlier Detection using IQR
Outliers are extreme values.
Formula:
Lower Limit = Q1 - 1.5 * IQR
Upper Limit = Q3 + 1.5 * IQR
Q1 = df["marks"].quantile(0.25)
Q3 = df["marks"].quantile(0.75)
IQR = Q3 - Q1
lower_limit = Q1 - 1.5 * IQR
upper_limit = Q3 + 1.5 * IQR
outliers = df[(df["marks"] < lower_limit) | (df["marks"] > upper_limit)]
print(outliers)
8
11. Summary Statistics in Pandas
print([Link]())
For categorical columns:
print([Link](include="object"))
For all columns:
print([Link](include="all"))
12. Frequency Count
Frequency means how many times each value appears.
print(df["gender"].value_counts())
print(df["passed"].value_counts())
Percentage frequency:
print(df["gender"].value_counts(normalize=True) * 100)
13. GroupBy Statistics
GroupBy is used to calculate statistics for each category.
Example:
Average marks by gender.
print([Link]("gender")["marks"].mean())
Multiple statistics:
9
print([Link]("gender")["marks"].agg(["mean", "median", "min", "max",
"std"]))
14. Covariance
Covariance tells whether two numerical variables move together.
If covariance is positive:
• Both variables increase together.
If covariance is negative:
• One variable increases and the other decreases.
If covariance is near zero:
• There may be little or no linear relationship.
cov_value = df["study_hours"].cov(df["marks"])
print(cov_value)
Problem with covariance:
Its value depends on the units of data, so it is difficult to compare.
15. Correlation
Correlation measures the strength and direction of relationship between two numerical variables.
Correlation value is always between -1 and +1.
• +1 means perfect positive relationship
• -1 means perfect negative relationship
• 0 means no linear relationship
corr_value = df["study_hours"].corr(df["marks"])
print(corr_value)
Correlation matrix:
10
print(df[["study_hours", "marks"]].corr())
Use correlation when:
• You want to understand relationship strength
• You want to compare relationships between different columns
16. Visualizing Statistics
import [Link] as plt
[Link](df["marks"])
[Link]("Marks")
[Link]("Frequency")
[Link]("Distribution of Marks")
[Link]()
Boxplot:
[Link](df["marks"])
[Link]("Marks")
[Link]("Boxplot of Marks")
[Link]()
Scatter plot:
[Link](df["study_hours"], df["marks"])
[Link]("Study Hours")
[Link]("Marks")
[Link]("Study Hours vs Marks")
[Link]()
17. Probability Basics
Probability measures the chance of an event happening.
Formula:
11
Probability = Favorable Outcomes / Total Outcomes
Example:
Probability of getting heads in a coin toss = 1 / 2 = 0.5
prob_head = 1 / 2
print(prob_head)
18. Random Variables
A random variable is a variable whose value depends on the outcome of a random event.
Example:
If we roll a dice, X can be 1, 2, 3, 4, 5, or 6.
import random
x = [Link](1, 6)
print(x)
19. Probability Distributions
A probability distribution tells how probabilities are distributed over possible values.
There are two main types:
19.1 Discrete Probability Distribution
Used for countable outcomes.
Examples:
• Dice roll
• Number of customers
• Number of clicks
12
19.2 Continuous Probability Distribution
Used for measurable values.
Examples:
• Height
• Weight
• Salary
• Time
20. Uniform Distribution
In uniform distribution, all outcomes have equal probability.
Example:
Rolling a fair dice.
import numpy as np
uniform_data = [Link](low=0, high=10, size=1000)
[Link](uniform_data, bins=30)
[Link]("Uniform Distribution")
[Link]()
21. Normal Distribution
Normal distribution is a bell-shaped distribution.
Many real-world values roughly follow normal distribution.
Examples:
• Height
• Exam marks
• Measurement errors
13
normal_data = [Link](loc=50, scale=10, size=1000)
[Link](normal_data, bins=30)
[Link]("Normal Distribution")
[Link]()
Here:
• loc = mean
• scale = standard deviation
22. Standard Normal Distribution
Standard normal distribution has:
• Mean = 0
• Standard deviation = 1
standard_normal = [Link](loc=0, scale=1, size=1000)
[Link](standard_normal, bins=30)
[Link]("Standard Normal Distribution")
[Link]()
23. Z-Score
Z-score tells how far a value is from the mean in terms of standard deviation.
Formula:
Z = (X - Mean) / Standard Deviation
x = 85
mean = df["marks"].mean()
std = df["marks"].std()
z_score = (x - mean) / std
print(z_score)
14
Interpretation:
• Z-score = 0 means value is equal to mean
• Positive z-score means value is above mean
• Negative z-score means value is below mean
• Z-score above 3 or below -3 can be considered extreme
24. Central Limit Theorem
Central Limit Theorem says:
If we take many samples from a population and calculate their means, the distribution of sample means will
become approximately normal, even if the original population is not normal.
This is very important because many hypothesis tests depend on normality.
population = [Link](scale=2, size=10000)
sample_means = []
for i in range(1000):
sample = [Link](population, size=30)
sample_means.append([Link]())
[Link](sample_means, bins=30)
[Link]("Central Limit Theorem")
[Link]()
25. Sampling Techniques
25.1 Random Sampling
Every row has equal chance of selection.
sample_df = [Link](n=4, random_state=42)
print(sample_df)
15
25.2 Stratified Sampling
Data is sampled while maintaining category proportions.
Useful for imbalanced data.
from sklearn.model_selection import train_test_split
train_df, test_df = train_test_split(
df,
test_size=0.25,
stratify=df["passed"],
random_state=42
)
print(train_df["passed"].value_counts(normalize=True))
print(test_df["passed"].value_counts(normalize=True))
26. Hypothesis Testing
Hypothesis testing is used to check whether a claim about data is statistically supported.
Important Terms
Null Hypothesis H0
The default assumption.
Usually says there is no effect, no difference, or no relationship.
Alternative Hypothesis H1
The claim we want to test.
Usually says there is an effect, difference, or relationship.
Alpha
Alpha is the significance level.
Common value:
16
alpha = 0.05
This means we accept a 5% chance of making a wrong rejection of the null hypothesis.
P-value
P-value tells how likely the observed result is if the null hypothesis is true.
Decision rule:
If p-value < alpha: Reject H0
If p-value >= alpha: Fail to reject H0
27. One-Tailed and Two-Tailed Tests
Left-Tailed Test
Used when the alternative hypothesis says the value is less than something.
Example:
Average app size is less than 25 MB.
Right-Tailed Test
Used when the alternative hypothesis says the value is greater than something.
Example:
Average rating is greater than 4.0.
Two-Tailed Test
Used when the alternative hypothesis says the value is different from something.
Example:
Average salary is different from 40,000.
17
28. Z-Test
Z-test is used when:
• Sample size is large, usually n >= 30
• Population standard deviation is known, or sample is large enough
• Data is numerical
Install statsmodels if needed:
pip install statsmodels
from [Link] import ztest
marks = df["marks"]
z_stat, p_value = ztest(
marks,
value=60,
alternative="larger"
)
alpha = 0.05
print("Z Statistic:", z_stat)
print("P-value:", p_value)
if p_value < alpha:
print("Reject Null Hypothesis")
else:
print("Fail to Reject Null Hypothesis")
Business question:
Is the average student mark significantly greater than 60?
29. T-Test
T-test is used when:
• Sample size is small
• Population standard deviation is unknown
18
• Data is numerical
29.1 One Sample T-Test
Used to compare sample mean with a fixed value.
from [Link] import ttest_1samp
marks = df["marks"]
t_stat, p_value = ttest_1samp(marks, popmean=60)
print("T Statistic:", t_stat)
print("P-value:", p_value)
if p_value < alpha:
print("Reject Null Hypothesis")
else:
print("Fail to Reject Null Hypothesis")
Business question:
Is the average mark different from 60?
29.2 Independent Two Sample T-Test
Used to compare means of two independent groups.
Example:
Do male and female students have different average marks?
from [Link] import ttest_ind
male_marks = df[df["gender"] == "Male"]["marks"]
female_marks = df[df["gender"] == "Female"]["marks"]
t_stat, p_value = ttest_ind(male_marks, female_marks, equal_var=False)
print("T Statistic:", t_stat)
print("P-value:", p_value)
if p_value < alpha:
19
print("Reject Null Hypothesis")
else:
print("Fail to Reject Null Hypothesis")
Use equal_var=False for Welch's t-test, which is safer when group variances may be different.
29.3 Paired T-Test
Used when the same subjects are measured twice.
Example:
Marks before training and after training.
from [Link] import ttest_rel
before = [50, 55, 60, 65, 70]
after = [60, 58, 65, 70, 78]
t_stat, p_value = ttest_rel(before, after)
print("T Statistic:", t_stat)
print("P-value:", p_value)
if p_value < alpha:
print("Reject Null Hypothesis")
else:
print("Fail to Reject Null Hypothesis")
30. ANOVA
ANOVA means Analysis of Variance.
It is used to compare the means of more than two groups.
Example:
Do students from different teaching methods have different average marks?
20
anova_df = [Link]({
"method": ["Online", "Online", "Online", "Offline", "Offline", "Offline",
"Hybrid", "Hybrid", "Hybrid"],
"marks": [70, 75, 72, 65, 68, 66, 80, 82, 78]
})
print(anova_df)
from [Link] import f_oneway
online = anova_df[anova_df["method"] == "Online"]["marks"]
offline = anova_df[anova_df["method"] == "Offline"]["marks"]
hybrid = anova_df[anova_df["method"] == "Hybrid"]["marks"]
f_stat, p_value = f_oneway(online, offline, hybrid)
print("F Statistic:", f_stat)
print("P-value:", p_value)
if p_value < alpha:
print("Reject Null Hypothesis")
else:
print("Fail to Reject Null Hypothesis")
Interpretation:
If p-value < 0.05, at least one group mean is significantly different.
Important:
ANOVA tells that a difference exists, but it does not directly tell which groups are different.
31. Chi-Square Test
Chi-square test is used for categorical variables.
It checks whether two categorical columns are related.
Example:
Is gender related to pass/fail result?
21
from [Link] import chi2_contingency
contingency_table = [Link](df["gender"], df["passed"])
print(contingency_table)
chi2_stat, p_value, dof, expected = chi2_contingency(contingency_table)
print("Chi-square Statistic:", chi2_stat)
print("P-value:", p_value)
print("Degrees of Freedom:", dof)
print("Expected Values:")
print(expected)
if p_value < alpha:
print("Reject Null Hypothesis")
else:
print("Fail to Reject Null Hypothesis")
Interpretation:
If p-value < 0.05, the two categorical variables are significantly related.
32. Correlation Test
Correlation test checks whether two numerical columns are significantly related.
from [Link] import pearsonr
corr, p_value = pearsonr(df["study_hours"], df["marks"])
print("Correlation:", corr)
print("P-value:", p_value)
if p_value < alpha:
print("Reject Null Hypothesis")
else:
print("Fail to Reject Null Hypothesis")
Business question:
Is there a significant relationship between study hours and marks?
22
33. Pearson, Spearman, and Kendall Correlation
Pearson Correlation
Used when:
• Both variables are numerical
• Relationship is linear
• Data is roughly normally distributed
print(df["study_hours"].corr(df["marks"], method="pearson"))
Spearman Correlation
Used when:
• Relationship is monotonic
• Data may not be normally distributed
• Data may be ordinal
print(df["study_hours"].corr(df["marks"], method="spearman"))
Kendall Correlation
Used when:
• Dataset is small
• Data is ordinal
print(df["study_hours"].corr(df["marks"], method="kendall"))
34. Confidence Interval
A confidence interval gives a range where the true population value is likely to exist.
Example:
A 95% confidence interval for average marks may be:
23
60 to 75
This means we are reasonably confident that the true average mark lies between 60 and 75.
import [Link] as stats
import numpy as np
marks = df["marks"]
confidence = 0.95
n = len(marks)
mean = [Link](marks)
std_error = [Link](marks)
ci = [Link](
confidence=confidence,
df=n-1,
loc=mean,
scale=std_error
)
print(ci)
35. Skewness
Skewness tells whether data is symmetric or tilted.
print(df["marks"].skew())
Interpretation:
• Skewness around 0 means data is nearly symmetric
• Positive skew means long tail on right side
• Negative skew means long tail on left side
36. Kurtosis
Kurtosis tells about the heaviness of tails in a distribution.
24
print(df["marks"].kurt())
High kurtosis means more extreme values.
Low kurtosis means fewer extreme values.
37. Normality Test
Normality tests check whether data follows a normal distribution.
Shapiro-Wilk Test
from [Link] import shapiro
stat, p_value = shapiro(df["marks"])
print("Statistic:", stat)
print("P-value:", p_value)
if p_value < alpha:
print("Data is not normally distributed")
else:
print("Data looks normally distributed")
38. Standardization
Standardization converts data to mean 0 and standard deviation 1.
Formula:
Z = (X - Mean) / Standard Deviation
Use standardization when:
• Data has different scales
• Using algorithms like Logistic Regression, KNN, SVM, PCA
from [Link] import StandardScaler
25
scaler = StandardScaler()
scaled_values = scaler.fit_transform(df[["study_hours", "marks"]])
scaled_df = [Link](scaled_values, columns=["study_hours_scaled",
"marks_scaled"])
print(scaled_df)
39. Normalization
Normalization usually scales data between 0 and 1.
Formula:
X_scaled = (X - Min) / (Max - Min)
Use normalization when:
• You want values in a fixed range
• Using distance-based models or neural networks
from [Link] import MinMaxScaler
scaler = MinMaxScaler()
normalized_values = scaler.fit_transform(df[["study_hours", "marks"]])
normalized_df = [Link](normalized_values, columns=["study_hours_norm",
"marks_norm"])
print(normalized_df)
40. Simple Linear Regression Statistics
Linear regression tries to find a relationship between input X and output y.
Example:
Predict marks using study hours.
from sklearn.linear_model import LinearRegression
X = df[["study_hours"]]
26
y = df["marks"]
model = LinearRegression()
[Link](X, y)
print("Intercept:", model.intercept_)
print("Slope:", model.coef_[0])
Equation:
marks = intercept + slope * study_hours
Prediction:
predicted_marks = [Link]([[6]])
print(predicted_marks)
41. R-Squared
R-squared measures how much variation in the target variable is explained by the model.
r2_score = [Link](X, y)
print(r2_score)
Interpretation:
If R-squared = 0.80, it means the model explains 80% of the variation in the target variable.
42. Important Statistical Tests Summary
Test Data Type Used For Python Function
Compare sample mean with
Z-Test Numerical ztest()
fixed value
One Sample T- Compare sample mean with
Numerical ttest_1samp()
Test fixed value
27
Test Data Type Used For Python Function
Independent T- Compare means of two
Numerical + 2 groups ttest_ind()
Test groups
Numerical before/
Paired T-Test Compare same group twice ttest_rel()
after
Numerical + 3 or more Compare means of multiple
ANOVA f_oneway()
groups groups
Relationship between
Chi-Square Categorical chi2_contingency()
categories
Pearson
Numerical Linear relationship pearsonr()
Correlation
Shapiro Test Numerical Normality check shapiro()
43. Which Test Should You Use?
Numerical column vs fixed value
Use:
• Z-test if sample is large
• T-test if sample is small or population standard deviation is unknown
Example:
Average app size vs 25 MB.
Numerical column vs two categories
Use independent t-test.
Example:
Average marks of male vs female students.
Numerical column vs more than two categories
Use ANOVA.
Example:
28
Average marks across Online, Offline, and Hybrid teaching methods.
Categorical column vs categorical column
Use Chi-square test.
Example:
Gender vs Pass/Fail.
Numerical column vs numerical column
Use correlation.
Example:
Study hours vs marks.
44. Complete Mini Statistics Project
import pandas as pd
import numpy as np
import [Link] as plt
from [Link] import ttest_ind, f_oneway, chi2_contingency, pearsonr, shapiro
from [Link] import ztest
# Dataset
students = [Link]({
"student_id": range(1, 21),
"gender": ["Male", "Female"] * 10,
"method": ["Online", "Offline", "Hybrid", "Online", "Offline"] * 4,
"study_hours": [2, 4, 3, 5, 6, 7, 4, 8, 3, 6, 5, 7, 2, 4, 6, 8, 5, 7, 3, 6],
"marks": [45, 60, 55, 70, 75, 85, 65, 90, 50, 78, 72, 88, 48, 62, 77, 92,
74, 86, 53, 80]
})
students["passed"] = [Link](students["marks"] >= 50, "Yes", "No")
print([Link]())
29
Descriptive Statistics
print([Link]())
print(students["gender"].value_counts())
print([Link]("gender")["marks"].mean())
Visualization
[Link](students["marks"], bins=10)
[Link]("Marks Distribution")
[Link]("Marks")
[Link]("Frequency")
[Link]()
Z-Test
Question:
Is the average mark greater than 65?
z_stat, p_value = ztest(students["marks"], value=65, alternative="larger")
print(z_stat, p_value)
if p_value < 0.05:
print("Reject H0: Average marks are significantly greater than 65")
else:
print("Fail to Reject H0: Not enough evidence")
Independent T-Test
Question:
Do male and female students have different average marks?
male = students[students["gender"] == "Male"]["marks"]
female = students[students["gender"] == "Female"]["marks"]
t_stat, p_value = ttest_ind(male, female, equal_var=False)
print(t_stat, p_value)
30
if p_value < 0.05:
print("Reject H0: Male and female average marks are different")
else:
print("Fail to Reject H0: No significant difference")
ANOVA
Question:
Do teaching methods have different average marks?
online = students[students["method"] == "Online"]["marks"]
offline = students[students["method"] == "Offline"]["marks"]
hybrid = students[students["method"] == "Hybrid"]["marks"]
f_stat, p_value = f_oneway(online, offline, hybrid)
print(f_stat, p_value)
if p_value < 0.05:
print("Reject H0: At least one teaching method has different average marks")
else:
print("Fail to Reject H0: No significant difference")
Chi-Square Test
Question:
Is gender related to pass/fail result?
contingency_table = [Link](students["gender"], students["passed"])
chi2_stat, p_value, dof, expected = chi2_contingency(contingency_table)
print(chi2_stat, p_value)
if p_value < 0.05:
print("Reject H0: Gender and pass/fail result are related")
else:
print("Fail to Reject H0: No significant relationship")
31
Correlation Test
Question:
Is study hours related to marks?
corr, p_value = pearsonr(students["study_hours"], students["marks"])
print(corr, p_value)
if p_value < 0.05:
print("Reject H0: Study hours and marks are significantly related")
else:
print("Fail to Reject H0: No significant relationship")
Normality Test
stat, p_value = shapiro(students["marks"])
print(stat, p_value)
if p_value < 0.05:
print("Marks are not normally distributed")
else:
print("Marks look normally distributed")
45. Common Mistakes in Statistics
Mistake 1: Using mean when data has outliers
Use median instead.
Mistake 2: Saying correlation means causation
Correlation does not prove causation.
Example:
Ice cream sales and drowning cases may both increase in summer, but ice cream does not cause drowning.
32
Mistake 3: Using t-test for more than two groups
Use ANOVA for more than two groups.
Mistake 4: Using chi-square for numerical data
Chi-square is for categorical data.
Mistake 5: Thinking p-value tells the probability that H0 is true
P-value does not directly tell that H0 is true or false.
It tells how likely the observed result is assuming H0 is true.
Mistake 6: Ignoring sample size
Very small samples can produce unreliable results.
Very large samples can make tiny differences statistically significant.
46. Statistics Roadmap for Data Science
Learn in this order:
1. Mean, median, mode
2. Variance and standard deviation
3. Percentiles, quartiles, IQR
4. Outlier detection
5. Probability basics
6. Probability distributions
7. Normal distribution
8. Z-score
9. Central Limit Theorem
10. Sampling
11. Confidence intervals
12. Hypothesis testing
13. Z-test
14. T-test
15. ANOVA
16. Chi-square test
17. Correlation
18. Regression basics
19. Statistical assumptions
33
20. Practical interpretation
47. Final Cheat Sheet
Center of Data
df["column"].mean()
df["column"].median()
df["column"].mode()
Spread of Data
df["column"].var()
df["column"].std()
df["column"].max() - df["column"].min()
Quartiles
df["column"].quantile(0.25)
df["column"].quantile(0.50)
df["column"].quantile(0.75)
Correlation
df[["col1", "col2"]].corr()
Group Statistics
[Link]("category_column")["numeric_column"].mean()
Z-Test
from [Link] import ztest
z_stat, p_value = ztest(data, value=known_mean)
34
T-Test
from [Link] import ttest_1samp, ttest_ind, ttest_rel
ANOVA
from [Link] import f_oneway
Chi-Square
from [Link] import chi2_contingency
Pearson Correlation Test
from [Link] import pearsonr
48. Best Practical Advice
Statistics is not about memorizing formulas only.
For Data Science, always ask:
1. What type of columns do I have?
2. Am I comparing averages or categories?
3. How many groups are there?
4. Is the data numerical or categorical?
5. What is my null hypothesis?
6. What is my alternative hypothesis?
7. What does the p-value say?
8. What is the business conclusion?
That is how statistics becomes useful in real projects.
35