Why check primary key uniqueness and duplicates early, and how does it relate to the unit of observation?

Quick Overview

An exploratory data analysis interview question on why you should identify a table's primary key and check it for duplicates before any analysis. It tests whether you understand the unit of observation, how duplicates and join fan-out distort metrics, and how to check keys in pandas and SQL.

Why check primary key uniqueness and duplicates early, and how does it relate to the unit of observation?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

Why is it important to identify the primary key and check for uniqueness and duplicates early in an analysis, and how does this relate to the unit of observation? ```hint Count two things Compare the number of rows with the number of distinct values of the column you believe identifies a row. ``` ```hint Think about joins Ask what happens to a sum after you join a table to another table that has several matching rows per key. ``` ### What a Strong Answer Covers - What a primary key is and how it relates to the grain, or unit of observation, of a table. - What a non-unique key tells you about what each row really represents. - Which metrics duplicates distort and where duplicates usually come from. - How to check uniqueness in practice, including composite keys and joins. ### Follow-up Questions - You join orders to payments and total revenue doubles. How do you find the cause and fix it? - Two rows share an `order_id` but differ in one column. How do you decide which one to keep? - How would you enforce the key check in a pipeline that runs every day? - When does a table have no single-column key, and how do you choose a composite key?

Overview: An exploratory data analysis interview question on why you should identify a table's primary key and check it for duplicates before any analysis. It tests whether you understand the unit of observation, how duplicates and join fan-out distort metrics, and how to check keys in pandas and SQL.

General logo
General
Nov 25, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

Why is it important to identify the primary key and check for uniqueness and duplicates early in an analysis, and how does this relate to the unit of observation?

What a Strong Answer Covers Guidance

  • What a primary key is and how it relates to the grain, or unit of observation, of a table.
  • What a non-unique key tells you about what each row really represents.
  • Which metrics duplicates distort and where duplicates usually come from.
  • How to check uniqueness in practice, including composite keys and joins.

Follow-up Questions Guidance

  • You join orders to payments and total revenue doubles. How do you find the cause and fix it?
  • Two rows share an order_id but differ in one column. How do you decide which one to keep?
  • How would you enforce the key check in a pipeline that runs every day?
  • When does a table have no single-column key, and how do you choose a composite key?