Skip to main content
Xenors Xenors
XENORS
Home › Data Science › the Python reference: Pandas, NumPy & ML
Module lesson · 45 of 45

Python Data Science Cheat Sheet: Pandas, NumPy & ML

A compact the Python reference for NumPy, Pandas, plotting, preprocessing, model training and evaluation.

By Ashok Kumar YadavHands-on examples + practiceDataset + notebook included
Python Data Science Cheat Sheet: Pandas, NumPy & ML

A compact the Python reference for NumPy, Pandas, plotting, preprocessing, model training and evaluation. For the Python reference, the examples stay small enough for you to predict the result before execution.

Editorial note: Publication metadata for Python Data Science Cheat Sheet is intentionally unset until this URL is actually released; the lesson already includes its own examples, CSV and notebook.

Build the mental model behind Ultimate the Python reference

A practical cheat sheet should let you move from CSV to baseline model quickly: read data, inspect, split, build a preprocessing pipeline, fit, predict and calculate a metric.

  • A useful cheat sheet groups commands by task: inspect, select, transform, aggregate, join, visualize and model.
  • Short examples are easier to remember when each one shows input shape and expected output.
  • Prefer idiomatic vectorized operations to unnecessarily complicated loops in NumPy and pandas.
  • A cheat sheet should point to full tutorials for edge cases instead of trying to encode every exception in one page.

Run small examples and inspect every intermediate object

For the Python reference, predict one visible result before each snippet runs—a row count, shape, statistic, ranking or error pattern—then compare it with the printed checkpoint.

Example 1 · Baseline example
# the Python reference · example 1
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression

X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, random_state=42)
model = make_pipeline(SimpleImputer(strategy='median'), StandardScaler(), LogisticRegression())
model.fit(X_train, y_train)
print(model.score(X_test, y_test))
Output / checkpoint
the Python reference checkpoint 1: Run the cell and inspect the printed values before changing anything.
Example 2 · Inspect data before transforming it
# the Python reference · example 2
import pandas as pd

df = pd.read_csv('practice.csv')
print(df.shape)
print(df.dtypes)
print(df.head(3).to_string(index=False))
Output / checkpoint
the Python reference checkpoint 2: (30, 5)
Column types are printed, followed by the first three rows.
Example 3 · Check missing values explicitly
# the Python reference · example 3
missing = df.isna().sum().sort_values(ascending=False)
print(missing[missing.gt(0)])
Output / checkpoint
the Python reference checkpoint 3: Only columns with at least one missing value are listed.
Example 4 · Create a reproducible summary
# the Python reference · example 4
summary = df.select_dtypes('number').agg(['count','mean','median','min','max']).T
print(summary.round(2))
Output / checkpoint
the Python reference checkpoint 4: A compact numeric summary appears with one row per numeric column.
Example 5 · Test one edge case
# the Python reference · example 5
test = df.copy()
if len(test):
    test.iloc[0, 0] = test.iloc[0, 0]
print('rows:', len(test), 'duplicates:', test.duplicated().sum())
Output / checkpoint
the Python reference checkpoint 5: The row count and duplicate count make the check visible instead of implicit.

Debug shape, dtype and missing-value problems

Verification habit

Prefer idiomatic vectorized operations to unnecessarily complicated loops in NumPy and pandas.

Failure mode to watch

A cheat sheet should point to full tutorials for edge cases instead of trying to encode every exception in one page.

Self-check with answers

For the Python reference, what result should you be able to explain without the code?

A useful cheat sheet groups commands by task: inspect, select, transform, aggregate, join, visualize and model.

Which assumption matters most in this the Python reference exercise?

Prefer idiomatic vectorized operations to unnecessarily complicated loops in NumPy and pandas.

What failure mode would make this the Python reference result untrustworthy?

A cheat sheet should point to full tutorials for edge cases instead of trying to encode every exception in one page.

Turn the lesson into a reusable notebook

Try it yourself workspace

Edit this the Python reference starter, copy it, and run it in the downloadable notebook or your local Jupyter environment.

Questions specific to this lesson

What should I inspect before using Ultimate the Python reference?

Short examples are easier to remember when each one shows input shape and expected output.

How do I debug a wrong result for the Python reference?

Print shape, dtypes and a few representative rows after each transformation. That usually reveals whether the issue is selection, missing data, joins or implicit type conversion.

Should I prefer a one-line expression or several steps for the Python reference?

Prefer the version you can test and explain. Compact code is useful only when the intermediate assumptions remain visible.

How can I practise this lesson for the Python reference?

Download the page-specific CSV and notebook, reproduce the examples, then add one column or edge case and document how the output changes.

Primary references and further reading

For the Python reference, use these primary references when exact syntax, defaults or formal definitions matter beyond the examples on this page.

AK
Written by Ashok Kumar Yadav

Ashok Kumar Yadav writes Xenors tutorials on applied AI, programming and data workflows. This the Python reference lesson is designed as a reproducible learning exercise rather than a keyword-first article.

GitHub · LinkedIn

Continue exploring