Data Science Cheat Sheet: Key Concepts, Code & Formulas

There are roughly 40 concepts a working data scientist reaches for repeatedly — things like p-values, gradient descent, confusion matrices, and Pandas merge types. Most practitioners learn them once, use them for a week, then spend the next year Googling them before every interview or new project. This data science cheat sheet collects the ones that actually matter: statistics, Python patterns, machine learning algorithms, and SQL — in one place, without padding.

Statistics Fundamentals: The Data Science Cheat Sheet You Actually Need

Statistics is where most self-taught data scientists have the biggest gaps. Here are the concepts that appear constantly in real work:

Descriptive Statistics

  • Mean: Sum of values / count. Sensitive to outliers.
  • Median: Middle value. Use this when your data is skewed.
  • Standard Deviation (σ): Average distance from the mean. Low σ = clustered; high σ = spread.
  • Variance (σ²): SD squared. Useful in algorithm math but hard to interpret directly.
  • Percentile: P90 means 90% of values fall below this number. Vital for latency and salary analysis.
  • Skewness: Positive = tail right, negative = tail left. Affects which models you can apply without transformation.

Inferential Statistics

  • p-value: Probability of seeing your result if the null hypothesis were true. Below 0.05 = conventionally "significant." Not the same as effect size.
  • Confidence Interval: A 95% CI means if you ran the experiment 100 times, 95 of those intervals would contain the true value. It does NOT mean 95% probability the true value is in this particular interval.
  • Type I Error (α): False positive. You rejected a true null. Rate controlled by significance level.
  • Type II Error (β): False negative. You failed to reject a false null. Power = 1 − β.
  • Central Limit Theorem: Sample means approach a normal distribution as n increases, regardless of the population distribution. This is why so much parametric statistics works in practice.

Correlation vs. Causation (the one everyone knows but still gets wrong)

  • Pearson r: Linear relationship, -1 to +1. Assumes normal distribution of both variables.
  • Spearman ρ: Rank-based. Handles non-linear monotonic relationships and is more robust to outliers.
  • Confounding variable: A third variable that causes both X and Y to move together. Never skip this question when presenting correlation findings.

Python and Pandas Patterns: Data Science Cheat Sheet for Code

These are the operations that appear in nearly every exploratory data analysis:

Loading and Inspecting Data

import pandas as pd

df = pd.read_csv('data.csv')
df.head()          # First 5 rows
df.shape           # (rows, columns)
df.dtypes          # Column types
df.describe()      # Count, mean, std, min, quartiles, max
df.isnull().sum()  # Missing values per column
df.nunique()       # Unique values per column

Filtering and Selecting

# Boolean filter
df[df['salary'] > 100000]

# Multiple conditions (use & and |, not 'and'/'or')
df[(df['salary'] > 100000) & (df['department'] == 'Engineering')]

# Select columns
df[['name', 'salary']]

# loc vs iloc
df.loc[0:5, 'salary']      # Label-based, inclusive end
df.iloc[0:5, 2]            # Position-based, exclusive end

Grouping and Aggregating

df.groupby('department')['salary'].mean()
df.groupby(['department', 'level']).agg({'salary': ['mean', 'median', 'count']})

Joins (the one everyone mixes up)

  • inner: Only rows present in both DataFrames
  • left: All rows from left, matched from right where possible
  • right: All rows from right, matched from left where possible
  • outer: All rows from both, NaN where no match
pd.merge(df1, df2, on='user_id', how='left')

Machine Learning Algorithms: Quick Reference

Most problems are solved with five or six algorithms. Know when to reach for each:

Supervised Learning

  • Linear Regression: Continuous output, assumes linear relationship. Fast, interpretable. Check: residuals should be normally distributed with constant variance.
  • Logistic Regression: Binary classification. Output is probability (0–1) via sigmoid. Good baseline before trying complex models.
  • Decision Trees: Interpretable. Prone to overfitting without pruning. Foundation for ensemble methods.
  • Random Forest: Ensemble of trees trained on random subsets. Robust to overfitting. Feature importances are useful but can be misleading with correlated features.
  • Gradient Boosting (XGBoost, LightGBM): Typically wins tabular competitions. Trains trees sequentially, each correcting the last. Slower to train than Random Forest, usually more accurate.
  • Support Vector Machine (SVM): Maximizes margin between classes. Works well in high-dimensional spaces (text classification). Kernel trick handles non-linear boundaries.

Unsupervised Learning

  • K-Means: Partition n observations into k clusters. You must specify k. Sensitive to initial centroids and outliers. Use elbow method or silhouette score to pick k.
  • PCA (Principal Component Analysis): Reduces dimensionality by projecting onto axes of maximum variance. Helpful for visualization and removing multicollinearity, not for final features in tree models.
  • DBSCAN: Density-based clustering. Finds arbitrary shapes, handles outliers (marks them as noise). No need to specify k.

Evaluation Metrics

  • Accuracy: Correct / Total. Misleading on imbalanced classes.
  • Precision: True Positives / (TP + FP). "Of what I predicted positive, how many were correct?"
  • Recall: True Positives / (TP + FN). "Of all actual positives, how many did I catch?"
  • F1 Score: Harmonic mean of precision and recall. Use when you need to balance both.
  • AUC-ROC: Area under the ROC curve. 0.5 = random, 1.0 = perfect. Threshold-independent evaluation.
  • RMSE: Root Mean Squared Error for regression. Penalizes large errors more than MAE.

SQL Patterns for Data Scientists

SQL is not optional. Most data you will ever analyze lives in a relational database, and even if your main tool is Python, you will write SQL to extract it.

Window Functions (the single most valuable thing to learn)

-- Running total
SUM(revenue) OVER (PARTITION BY user_id ORDER BY date)

-- Row number within group
ROW_NUMBER() OVER (PARTITION BY department ORDER BY salary DESC)

-- Lag and lead (compare to previous/next row)
LAG(revenue, 1) OVER (ORDER BY date) AS prev_revenue

CTEs over Subqueries

WITH monthly_revenue AS (
  SELECT DATE_TRUNC('month', order_date) AS month,
         SUM(amount) AS revenue
  FROM orders
  GROUP BY 1
)
SELECT month,
       revenue,
       revenue - LAG(revenue) OVER (ORDER BY month) AS mom_change
FROM monthly_revenue

Top Courses to Build These Skills

A cheat sheet is a reference, not a curriculum. If you have gaps in any of the areas above, these courses cover them with real exercises:

Introduction to Data Analytics

IBM's foundation course on Coursera covers data types, analysis workflows, and visualization — the right starting point if statistics or Python are still fuzzy for you. Rated 9.8/10 across thousands of completions.

Tools for Data Science

Covers the actual environment setup — Jupyter, RStudio, GitHub, Watson Studio — that most tutorials skip. If you've been confused about how tools fit together, this is the practical orientation you need.

Python for Data Science, AI & Development by IBM

Goes from Python basics through Pandas, NumPy, and API access. Rated 9.8/10 and directly maps to the code patterns in this cheat sheet — good for drilling the syntax until it sticks.

Process Data from Dirty to Clean

Part of the Google Data Analytics Certificate. Focuses entirely on data cleaning — handling nulls, fixing types, outlier detection — which is what actually consumes 60–80% of a real project's time.

Analyze Data to Answer Questions

The follow-on course that takes clean data through aggregation, grouping, and SQL analysis. Structured around the kinds of business questions you will actually be asked to answer.

Python Data Science (edX)

A more rigorous ML-focused Python course rated 9.7/10. Better for people who already know Python basics and want to move into scikit-learn, model evaluation, and feature engineering.

FAQ

What should a data science cheat sheet include?

A useful cheat sheet covers four domains: statistics (distributions, hypothesis testing, correlation), Python/Pandas (data loading, filtering, groupby, joins), machine learning (algorithm selection, evaluation metrics), and SQL (window functions, CTEs, aggregations). Anything beyond that is usually better handled by documentation than memorization.

Is a data science cheat sheet enough to pass a technical interview?

No. Cheat sheets are reference material, not preparation material. Interviewers probe reasoning: why you chose one algorithm over another, how you would handle class imbalance, what you would do if your model's training and validation metrics diverge. You need to understand the concepts, not just recognize the terms.

What Python libraries does every data scientist need to know?

The core stack: NumPy (array math), Pandas (tabular data), Matplotlib/Seaborn (visualization), scikit-learn (ML models and preprocessing), and Jupyter (notebook environment). For production or large datasets, add SQLAlchemy (database connections) and optionally Polars (faster Pandas alternative).

Should I learn R or Python for data science?

Python. The job market is clear on this — Python appears in roughly 4× more data science job postings than R. R is still used in academic research and some biostatistics roles, but Python has better ML library support, better deployment options, and a larger community. Learn R later if your specific role requires it.

What statistics do I actually need to know as a data scientist?

You need solid understanding of: probability distributions (normal, binomial, Poisson), hypothesis testing (t-test, chi-squared, ANOVA), correlation and regression, and Bayesian thinking (prior, likelihood, posterior). Deep mathematical proofs are optional unless you're doing research. Applied understanding plus the ability to check your assumptions matters more than derivations.

How long does it take to learn data science from scratch?

A realistic timeline to land a junior role: 9–18 months of consistent study if you're starting from no programming background. If you already know Python or have a statistics background, 6–12 months is achievable. The bottleneck is usually portfolio projects, not coursework — employers want evidence you can complete a real analysis end to end.

Bottom Line

The concepts in this data science cheat sheet — from p-values to gradient boosting to window functions — are the ones that come up repeatedly in real work and technical interviews. Bookmark it, but don't stop there: a cheat sheet tells you the vocabulary; courses and projects build the judgment to apply it correctly.

If you're building skills from scratch, start with Introduction to Data Analytics for the foundations, then move into Python for Data Science by IBM for hands-on code. If SQL is your gap, the Analyze Data to Answer Questions course covers exactly the aggregation and window function patterns that appear most often in real roles.

Looking for the best course? Start here:

Related Articles

More in this category

Course AI Assistant Beta

Hi! I can help you find the perfect online course. Ask me something like “best Python course for beginners” or “compare data science courses”.