How to use the Pandas Cheat Sheet
- 1. Search a taskType a word like missing, groupby or merge.
- 2. Filter by groupImport, inspect, select, filter, clean, group and more.
- 3. Copy or downloadCopy a snippet, or download the whole sheet as text.
What's in the sheet
The snippets follow the order of a typical analysis:
- Import and create: read_csv, read_excel, read_json, read_sql and building a DataFrame from a dict.
- Inspect: head, shape, info, describe, dtypes and value_counts.
- Select and filter: columns, loc and iloc, conditions with & and |, isin, str.contains, query and isna.
- Clean: missing values, duplicates, renaming, type changes, trimming text, to_numeric and to_datetime.
- Add columns, sort, group and combine: np.where, pd.cut, sort_values, groupby with named aggregates, pivot_table, crosstab, merge, concat, melt and pivot.
- Dates and export: .dt parts, resample, rolling averages, to_csv, to_excel and to_json.
SQL to pandas, with an example
If you already know SQL, the second table maps 12 common clauses to pandas. For example, this SQL:
SELECT city, AVG(marks) FROM students
WHERE marks >= 40
GROUP BY city
ORDER BY 2 DESC;becomes one pandas chain:
(df[df["marks"] >= 40]
.groupby("city")["marks"].mean()
.sort_values(ascending=False))Three habits that save time: wrap each condition in brackets when you combine them with & or |; use reset_index() after groupby when you want a normal table back; and prefer vectorised code like df["a"] * df["b"] over apply, which is much slower on large data. The snippets use pandas 2.x syntax; one note marks where pandas 2.2 renamed the month-end alias from "M" to "ME".
Frequently asked questions
Which pandas version is this for?
pandas 2.x. Almost everything also works in 1.5.
Why do I get SettingWithCopyWarning?
You changed a filtered slice. Use .loc[rows, col] = value on the original, or add .copy() after filtering.
Do I need NumPy too?
pandas installs it. Import numpy as np when you use np.where or other NumPy functions.
Do I have to pay for the pandas cheat sheet?
No, it is free. Downloading the sheet asks for your name and WhatsApp number one time only. Then the pandas cheat sheet and all other Uncodemy tools stay open for you with no form.