Data Science Cheat Sheet: Python, Stats & ML Quick Reference

Most working data scientists spend an embarrassing amount of time Googling the same dozen things: how to reshape a pandas DataFrame, which metric to use for imbalanced classes, the exact syntax for a seaborn heatmap. This data science cheat sheet exists so you stop losing ten minutes per lookup. It covers the Python stack, core statistics, ML algorithm selection, and model evaluation — organized the way a practitioner actually thinks, not the way a textbook is structured.

The Python Data Science Cheat Sheet: Libraries You'll Use Every Day

Python dominates data science because of its ecosystem, not the language itself. Here is what each major library actually does and when you reach for it:

NumPy

The foundation everything else builds on. Use it for array math, linear algebra, and random number generation. If you are doing element-wise operations on large datasets, NumPy is faster than plain Python by orders of magnitude. Key things to know: np.where(), np.reshape(), broadcasting rules, and np.linalg for matrix decomposition.

Pandas

Your go-to for tabular data. The operations you will use constantly:

  • df.groupby().agg() — split-apply-combine aggregations
  • df.merge() — SQL-style joins (inner, left, right, outer)
  • df.pivot_table() — cross-tabulations
  • df.apply() — row/column-wise functions (slow; use vectorized ops first)
  • pd.get_dummies() — one-hot encoding for categorical columns
  • df.melt() / df.stack() — wide-to-long reshaping

Common gotcha: df['col'].value_counts(dropna=False) to catch NaN counts that value_counts() hides by default.

Scikit-learn

The standard ML library. Its consistent API (fit(), predict(), transform()) means switching algorithms costs almost nothing. Critical modules: sklearn.preprocessing for scaling and encoding, sklearn.model_selection for cross-validation and hyperparameter search, sklearn.pipeline for chaining steps without data leakage.

Matplotlib and Seaborn

Matplotlib gives you control; seaborn gives you speed. Use seaborn for EDA (heatmaps, pairplots, violin plots). Drop to matplotlib when you need a custom layout or publication-quality formatting. The one line you will write a hundred times: fig, axes = plt.subplots(nrows, ncols, figsize=(w, h)).

Statistics Cheat Sheet: The Formulas That Actually Come Up

You do not need to memorize every distribution. You do need to know when each one applies and what the key parameters mean.

Descriptive Stats Quick Reference

  • Mean vs Median: Use median when the distribution is skewed or has outliers. Salary data, house prices, response times — always start with median.
  • Standard Deviation vs IQR: SD is sensitive to outliers (it squares deviations). IQR (Q3 − Q1) is robust. For outlier detection, IQR is usually more informative.
  • Skewness: Positive skew = long right tail (most values low, a few very high). Negative skew = long left tail. Log-transform is the standard fix for positive skew.
  • Kurtosis: Measures tail heaviness. High kurtosis = more extreme outliers than a normal distribution would produce.

Key Probability Concepts

  • Bayes' theorem: P(A|B) = P(B|A) × P(A) / P(B). Comes up in Naive Bayes, spam filtering, and any time you update a prior with new evidence.
  • Central Limit Theorem: Sample means approach a normal distribution as n increases, regardless of the original distribution. This is why so many statistical tests assume normality — they are applied to means, not raw data.
  • p-value: The probability of observing your result (or more extreme) given the null hypothesis is true. It is not the probability the null is true. This distinction matters; misinterpreting it is one of the most common errors in data analysis.
  • Confidence interval: If you repeated the experiment 100 times, approximately 95 of those intervals would contain the true parameter. Not "there's a 95% chance the true value is in this interval."

Hypothesis Testing Cheat Sheet

  • t-test: Compare means of two groups. Use Welch's t-test (unequal variances) by default.
  • Chi-square test: Compare categorical distributions or test independence between two categorical variables.
  • ANOVA: Compare means across three or more groups. If significant, follow up with Tukey's HSD to find which pairs differ.
  • Mann-Whitney U: Non-parametric alternative to the t-test. Use when normality assumption is violated and n is small.

ML Algorithm Selection Cheat Sheet

Choosing an algorithm is not about what is most sophisticated. It is about what fits your data structure, size, and interpretability requirements.

Classification

  • Logistic Regression: Start here. Fast, interpretable, strong baseline. Works well when the relationship is roughly linear in log-odds space.
  • Random Forest: Strong default for tabular data. Handles nonlinear relationships and mixed feature types with minimal preprocessing. Check feature importances to understand it.
  • Gradient Boosting (XGBoost, LightGBM, CatBoost): Usually the best-performing option on structured data. LightGBM is fastest; CatBoost handles categoricals natively without encoding.
  • SVM: Useful in high-dimensional spaces (text, genomics). Slow on large datasets. Rarely the first choice in 2024+ for general tabular work.
  • Neural Networks: Best for images, audio, text, and very large datasets where feature engineering is impractical. Overkill for most business tabular problems.

Regression

  • Linear Regression: Baseline. Always run it first to establish how much of a gain more complex models give you.
  • Ridge / Lasso: Regularized linear regression. Lasso performs feature selection (drives coefficients to zero); Ridge shrinks them proportionally. Use ElasticNet to get both.
  • Tree-based regressors: Same gradient boosting frameworks apply. Good at capturing interactions without explicit feature engineering.

Unsupervised Learning

  • K-Means: Fast, scalable, assumes spherical clusters of similar size. Sensitive to outliers and requires choosing k in advance. Use the elbow method or silhouette score to pick k.
  • DBSCAN: Finds arbitrarily shaped clusters, identifies outliers as noise. Better than k-means when cluster shapes are irregular.
  • PCA: Dimensionality reduction via variance maximization. Use before visualizing high-dimensional data or when you need to remove correlated features.

Model Evaluation Cheat Sheet

Picking the wrong metric is one of the most expensive mistakes in applied ML. Here is how to match the metric to the problem:

Classification Metrics

  • Accuracy: Only use when classes are balanced. 99% accuracy on a fraud dataset where 1% of transactions are fraud just means your model predicts "not fraud" for everything.
  • Precision: Of all positive predictions, how many were correct? Use when false positives are costly (e.g., flagging legitimate transactions as fraud).
  • Recall (Sensitivity): Of all actual positives, how many did you catch? Use when false negatives are costly (e.g., missing a cancer diagnosis).
  • F1 Score: Harmonic mean of precision and recall. Good single metric for imbalanced classes.
  • AUC-ROC: Model's ability to discriminate across all thresholds. Use for comparing models; do not use as a final metric when you need a specific operating point.
  • Log Loss: Penalizes confident wrong predictions heavily. Use when you care about calibrated probability outputs, not just the class label.

Regression Metrics

  • MAE (Mean Absolute Error): Average absolute deviation. Interpretable in original units. Robust to outliers.
  • RMSE (Root Mean Squared Error): Penalizes large errors more heavily than MAE. Use when large errors are particularly bad.
  • R² (Coefficient of Determination): Proportion of variance explained. Useful for comparing models on the same dataset; meaningless across datasets with different variance.

Top Courses to Build These Skills

A cheat sheet tells you what things are. A structured course tells you how to use them under pressure. These are the ones worth your time:

Introduction to Data Analytics

Covers the full analytical workflow from data collection through visualization and storytelling — a solid foundation before you dive into ML-heavy content. Rated 9.8 on Coursera.

Tools for Data Science

Specifically covers the practitioner toolset — Jupyter, GitHub, Watson Studio, and the Python/R ecosystem in context. Good if you want to understand not just the algorithms but the environment they run in. Rated 9.8 on Coursera.

Python for Data Science, AI & Development by IBM

IBM's hands-on course that covers NumPy, Pandas, and APIs in a practical sequence. Pairs well with this cheat sheet because you will actually write the code, not just read about it. Rated 9.8 on Coursera.

Process Data from Dirty to Clean

Data cleaning is where most practitioners spend 60-80% of their time. This course addresses that directly instead of pretending your data comes pre-tidy. Rated 9.8 on Coursera.

Analyze Data to Answer Questions

Focuses on the analysis phase specifically — aggregation, filtering, and interpreting results to support decisions. Good for sharpening the analytical judgment that no cheat sheet can give you. Rated 9.8 on Coursera.

Python Data Science (EDX)

A solid alternative track through EDX for learners who prefer a university-paced structure over self-directed modules. Rated 9.7. Worth considering if Coursera's format does not suit your learning style.

FAQ

What should a data science cheat sheet include?

At minimum: the core Python libraries (NumPy, Pandas, Scikit-learn, Matplotlib), key statistical concepts (hypothesis testing, distributions, p-values), ML algorithm selection guidance, and model evaluation metrics. Preprocessing steps (scaling, encoding, handling missing values) are often overlooked but belong on any practical reference.

Is there an official Python data science cheat sheet?

No single official one exists. DataCamp publishes well-maintained cheat sheets for Pandas, NumPy, Scikit-learn, and Matplotlib separately, as does the Scikit-learn documentation itself. For SQL, Mode Analytics has a good reference. The value of a consolidated cheat sheet like this one is that you do not have to switch between five browser tabs during a project.

How do I remember which ML algorithm to use?

The Scikit-learn algorithm selection flowchart is the most-used shortcut: it walks you from sample size and label availability to a suggested algorithm. More practically: start with a linear model as a baseline, add gradient boosting if you need better performance, and only reach for neural networks if the simpler models plateau and you have enough data to train them.

What statistical concepts do data scientists actually use day-to-day?

In practice: descriptive statistics (mean, median, variance, IQR), A/B testing (t-tests, chi-square, sample size calculation), correlation vs causation, and the basics of probability distributions. Bayesian inference comes up in marketing attribution, fraud detection, and experimentation. Most practitioners rarely use ANOVA or survival analysis outside of specific domains.

What is the difference between data science and data analytics?

Data analytics is primarily about describing what happened — dashboards, reports, aggregations, trend analysis. Data science adds prediction and automation: building models that generalize to new data. In practice the roles overlap heavily, and many "data scientist" job descriptions are really analyst roles with a Python requirement. Check the actual job responsibilities, not just the title.

Do I need to know math to use this data science cheat sheet effectively?

For most applied work: linear algebra (matrix operations, dot products), basic calculus (understanding gradient descent conceptually), and statistics at the level covered in this article. You do not need to derive backpropagation by hand to build useful models, but knowing what a gradient is and why regularization prevents overfitting will save you from a lot of bad decisions.

Bottom Line

This data science cheat sheet is a reference, not a curriculum. Bookmark the sections you forget repeatedly — for most people that is model evaluation metrics and the exact Pandas syntax for reshaping data. The algorithm selection guide is the part to internalize rather than just look up; understanding why you choose a particular model matters more than memorizing its hyperparameters.

If you find yourself returning to this page often, that is a signal to go deeper on the underlying concepts. The courses above are organized to take you from "I can run this code" to "I understand why it works and what to do when it does not." That gap is where most junior practitioners stall out, and closing it is what separates people who get promoted from people who stay in analyst roles indefinitely.

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”.