#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
⚡ FREE · SEARCHABLE

Pandas Cheat Sheet: The Code You Need for Everyday Data Work

Search 61 pandas snippets by task and see the SQL equivalent of common queries.

  • 🔎 61 snippets in 11 groups
  • 🗃️ SQL to pandas
  • ⬇️ Downloadable

How to use the Pandas Cheat Sheet

  1. 1. Search a taskType a word like missing, groupby or merge.
  2. 2. Filter by groupImport, inspect, select, filter, clean, group and more.
  3. 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.

More free tools

See all free tools