Cheat sheet · Specialise
Pandas cheat sheet
Opens with creditsA quick-revision book on pandas for anyone cleaning and analysing tabular data in Python: loading files, selecting and filtering, fixing missing values, grouping, joining, reshaping and working with dates. Snippets follow current pandas, where copy-on-write is the default and chained assignment no longer works.
Chapters
10 chapters · 63 concepts
1Loading and saving dataThe two objects pandas is built on, how to read CSV, Excel, SQL and Parquet into them, and how to write results back out.6 concepts
- 1DataFrame and SeriesA Series is one labelled column of values with a single dtype.
- 2read_csv
pd.read_csvreads a delimited text file into a DataFrame, guessing column types. - 3Excel, SQL, JSON and Parquetpandas has a reader for each common source:
read_excelfor workbooks,read_sqlfor a database query,read_jsonfor JSON andread_parquetfor columnar… - 4Writing data outEvery reader has a writer:
to_csv,to_excel,to_parquet,to_sql. - 5Why Parquet over CSVParquet is a compressed, columnar file format that stores each column's type alongside the data.
- 6First look at a dataset
head()shows the first rows,shapethe row and column count,info()each column's dtype and non-null count, anddescribe()summary statistics.
6 in this chapterOpen this chapter2Selecting rows and columnsPicking columns, the difference between
locandiloc, the index, and how copy-on-write changes what happens when you modify a selection.6 concepts- 1Selecting columnsSquare brackets with one name return a Series; with a list of names they return a DataFrame with those columns in that order.
- 2loc: select by label
df.loc[rows, cols]selects by index labels and column names, and accepts boolean masks. - 3iloc: select by position
df.iloc[rows, cols]selects by integer position, like Python lists: the end of a slice is excluded. - 4The indexThe index is the set of row labels.
- 5Copy-on-writeSince pandas 3.0 every selection or method result behaves as a new object: changing it never changes the original. pandas only copies data when you actually…
- 6Sampling rows
sample(n)orsample(frac=0.1)picks random rows;nlargestandnsmallestreturn the top or bottom rows by a column.
6 in this chapterOpen this chapter- Filtering and sortingBoolean masks, combining conditions,
query, membership tests and sorting.6 conceptsOpens with credits - Cleaning and missing valuesFinding and handling missing values, fixing types, removing duplicates and renaming columns.7 conceptsOpens with credits
- New columns and transformationsCreating columns with vectorised maths,
assign,pd.col, conditional logic, binning,mapandapply, and text and category helpers.7 conceptsOpens with credits - Grouping and aggregatingSplit, apply, combine:
groupbywith named aggregations,transform, counting, pivot tables and crosstabs.7 conceptsOpens with credits - Merge, join and concatCombining tables side by side on keys, stacking them on top of each other, and checking that a join did what you expected.6 conceptsOpens with credits
- ReshapingSwitching between long and wide tables with
melt,pivot,stackandunstack, and expanding list columns.5 conceptsOpens with credits - Dates and time seriesParsing dates, the
.dtaccessor, resampling, rolling windows, shifts and time zones.7 conceptsOpens with credits - Performance and good habitsKeeping pandas fast and memory-light, and writing analysis code others can rerun.6 conceptsOpens with credits
- 11Glossary, A to ZEvery concept in the sheet and the smaller terms it uses, in one list.74 terms
About this sheet
Reading data, selecting, filtering, missing values, groupby, merge and join, reshaping and dates in pandas, with copy-on-write in mind.
Related on Sefism
Picked from the other libraries by shared topics.
Roadmaps
See allBest practices
See all- Data Pipeline Best PracticesHow to build data pipelines you can re-run, test and trust: idempotent tasks, orchestrator hygiene, layered transformations, data tests, freshness, ownership and monitoring.
- Data Analysis Best PracticesAn analyst's workflow in SQL, pandas and Polars: framing the question, reading data correctly, joins and grain, aggregation pitfalls, reproducible notebooks, checking results and sharing findings.
- Data Modeling Best PracticesDimensional data modeling for analytics: declaring the grain, fact and dimension tables, slowly changing dimensions, dbt marts, naming, tests, contracts and a semantic layer.
Checklists
See all- Data Quality ChecklistA data quality checklist for warehouse tables: ownership, freshness, volume, schema, nulls, uniqueness, referential checks, anomaly monitoring and data incidents, with how to verify each.
- Analytics Dashboard ChecklistAn analytics dashboard checklist for launch day: purpose and audience, metric definitions, data freshness, correctness, performance, access, accessibility, ownership and adoption.
- ML Model Deployment ChecklistAn ML model deployment checklist: baselines, training and serving consistency, validation, model registry, canary rollout, rollback, drift monitoring and ownership, with how to verify each.
Project structures
See all- dbt project project structureA dbt project that turns raw tables into tested, documented models, using the staging, intermediate and marts layers from dbt's own structure guide. It runs on DuckDB on your laptop, so you can learn analytics engineering for free, and grows into a governed project with checks, contracts, slim CI and a hosted docs site that moves to BigQuery or Snowflake unchanged.
- Apache Airflow project structureFor data engineers scheduling real pipelines with Airflow 3. It starts from
astro dev init(dags, include, plugins, tests and a Runtime Dockerfile that runs Airflow locally in Docker) and grows into dags grouped by business area, logic in a tested include package, asset-driven scheduling, data quality checks, alerts, CI that parses and tests every dag, and dag-only deploys. A self-hosted docker compose and Helm route is shown alongside. - GenAI RAG app (FastAPI) project structureFor developers turning a "chat with your documents" demo into an app people can rely on. A FastAPI backend where every layer has a home: ingestion workers, retrieval, prompts as versioned files, model clients with fallbacks and cost caps, guards, evals that gate CI, and tracing, so a wrong answer can be traced to the step that caused it.
Career questions
See all- What is the difference between a data analyst, a data scientist and a machine learning engineer?Analysts answer business questions with SQL, spreadsheets, dashboards and reports. Data scientists add statistics, experiments and predictive models. ML engineers build and run models inside production software. Titles vary by company, so read the work in the job advert, and pick by the kind of problem you enjoy, not the title that sounds most senior.
- Should I learn Python or R for data science?For most people aiming at industry jobs, learn Python first: it covers analysis, machine learning and production code, and most data job adverts ask for it. Choose R first if you are heading into statistics, academic research, public health or survey work, where it is strong. Either way, SQL comes too, and the concepts transfer.
- Can I get into tech without a computer science degree?Yes, but not by collecting courses. Choose a role that uses what you already know, learn the specific skills that role needs, build proof you can show, and expect six to eighteen months of consistent work before the first offer.
Stuck on something specific?
Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.
- 1:1 Mentorship
- Fresh Graduate Mentorship
- Career Guidance
Brand deals, promos and partnerships: tauseeffayyaz@gmail.com