Sefism is free for learners. We are here to help you grow, one step at a time.Join for free
Sefism.

Best practices · Data and ML

Data Analysis Best Practices

Opens with credits

Best practices for answering questions with data in SQL, pandas and Polars, checked against Google's Good Data Analysis guide and the pandas, Polars and PostgreSQL documentation. It covers framing the question, reading data correctly, joins and grain, aggregation pitfalls, reproducible notebooks, checking results and communicating findings.

Written by Tauseef Fayyaz7 chapters, 28 practicesAbout 18 min24 quiz questionsReviewed 13 October 2026

What you will learn

7 chapters · about 18 min

  1. 1Frame the question firstAn analysis is only as useful as the question behind it. These practices pin down what you are measuring and why before you write a query.4 practices · 3 min
  2. 2Read the data correctlySummary numbers hide most problems. These practices get you looking at what a row means, how values are distributed and how your tools read types.4 practices · 3 min
  3. Joins without surprisesA join that changes the number of rows you expected is the most common silent error in analysis. These practices check cardinality, unmatched rows and nulls every time.4 practices · 3 minOpens with credits
  4. Aggregation pitfallsAggregates compress thousands of rows into one number, and the compression hides mistakes. These practices cover nulls, ratios, additivity and slicing.4 practices · 3 minOpens with credits
  5. Reproducible notebooks and codeIf you cannot rerun an analysis next month and get the same numbers, you cannot defend it. These practices make notebooks and queries repeatable.4 practices · 2 minOpens with credits
  6. Check your results before trusting themSurprising results are usually bugs. These practices, mostly from Google's Good Data Analysis guide, help you tell a finding from a mistake.4 practices · 2 minOpens with credits
  7. Communicate findingsAn analysis only helps if people understand it and trust it. These practices make the answer, its limits and its evidence clear.4 practices · 2 minOpens with credits

About this guide

Most wrong numbers in a report are not caused by hard statistics. They come from ordinary steps done carelessly: a join that quietly duplicated rows, an average of averages, a filter nobody wrote down, a notebook that only works when its cells run in a lucky order. These data analysis best practices are the habits that stop those mistakes before a chart reaches a meeting.

The guide follows an analyst's workflow from start to finish. It begins with the question, because an analysis that starts from a dataset or a favourite technique tends to answer something nobody asked. It then covers reading the data the way it was actually collected, joining tables without changing their grain, aggregating without the classic traps, keeping notebooks reproducible, checking results before trusting them, and writing up findings so people can act on them.

Examples use SQL with PostgreSQL 18, pandas 3.0 and Polars 2.0. Both pandas and Polars changed defaults in their latest major versions: pandas 3.0 turns on Copy-on-Write and a dedicated string type, and Polars 2.0 runs lazy queries on its streaming engine, which does not keep row order unless you ask. Where those changes affect everyday analysis, the guide says so.

Much of the process advice comes from Google's Good Data Analysis guide by Patrick Riley, which is worth reading in full. If you also build the pipelines and tables you analyse, the data pipeline and data modeling guides in this library pick up where this one stops.

Common questions

What are the main steps of a data analysis?

Start with a written question and the decision it informs. Then learn how the data was collected, validate it, describe what it shows, and only then judge what that means. Check results against past numbers and other sources, and write up the answer first, followed by evidence, method and caveats.

Why does my join return more rows than expected?

The key you joined on is not unique on one side, so each matching row is repeated. Check uniqueness before joining, pass validate="m:1" or "1:1" in pandas and Polars, and compare row counts before and after the join.

Why does SUM return null in SQL instead of zero?

In PostgreSQL and standard SQL, every aggregate except count returns null when no rows are selected. Wrap the result in coalesce(sum(x), 0) if an empty set should count as zero.

Should I use pandas or Polars for analysis?

Both work well. pandas has the larger ecosystem and, from version 3.0, Copy-on-Write and a dedicated string type by default. Polars is built around expressions and lazy queries, and from version 2.0 runs lazy queries on a streaming engine that does not keep row order unless asked. Pick one per project and learn its defaults.

How do I make a Jupyter notebook reproducible?

Put parameters such as date ranges and random seeds in one cell, use fixed dates rather than relative ones, pin library versions in a lock file, and restart the kernel and run all cells before sharing. Move reusable code into a module the notebook imports.

Sources (8)

Checked against these, last on 13 October 2026.

  1. Good Data Analysis, Google for Developersdevelopers.google.com/machine-learning/guides/good-data-analysis
  2. pandas.merge, pandas docspandas.pydata.org/docs/reference/api/pandas.merge.html
  3. What's new in 3.0.0, pandas docspandas.pydata.org/docs/whatsnew/v3.0.0.html
  4. polars.DataFrame.join, Polars docsdocs.pola.rs/api/python/stable/reference/dataframe/api/polars.DataFrame.join.html
  5. Version 2 upgrade guide, Polars docsdocs.pola.rs/releases/upgrade/2/
  6. Aggregate Functions, PostgreSQL docswww.postgresql.org/docs/current/functions-aggregate.html
  7. Subquery Expressions, PostgreSQL docswww.postgresql.org/docs/current/functions-subquery.html
  8. Modeling Fact Tables in Warehouse, Microsoft Learnlearn.microsoft.com/en-us/fabric/data-warehouse/dimensional-modeling-fact-tables

Picked from the other libraries by shared topics.

Work with me

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