KatInterview

Series vs DataFrame, WHERE vs HAVING, and Finding Repeated Emails

SQL & DataModel answer
EasyModel answerSQL & Datasqlpandasgroup-by

Last updated

Three short data-engineering questions: contrast pandas Series and DataFrame, explain when SQL applies WHERE versus HAVING, and write a query that reports emails occurring more than once.

Answer the three short questions below, as you would in a screening conversation for an entry-level data engineering role.

Part 1: pandas

What distinguishes a pandas Series from a pandas DataFrame? Give one realistic situation where you would reach for each.

Part 2: SQL filtering

Explain how WHERE differs from HAVING. When is each one the right choice, and why can't one always stand in for the other?

Part 3: Query

Consider this table:

customer_events

ColumnType
event_idBIGINT
customer_emailSTRING
source_systemSTRING
created_atTIMESTAMP (stored in UTC)

Write a SQL query that finds every customer_email that shows up more than once across the entire table. Return:

  • customer_email
  • duplicate_count (how many times that email appears)

Only emails with a count above 1 should be returned.

Besides the query, state any assumptions or edge cases you would raise (for example NULL values or inconsistent formatting), and describe how you would do the same thing in pandas.

Hints

Hint 1

Think of a Series as one labeled column and a DataFrame as several such columns sharing a row index. What does `df['col']` return versus `df[['col']]`?

Hint 2

Write out the logical order in which SQL evaluates clauses: FROM, WHERE, GROUP BY, aggregates, HAVING, SELECT. At which point do group counts first exist?

Hint 3

For the query, group by the email, count rows per group, and filter on the count after grouping. Then ask what happens to rows where the email is NULL, and whether the timestamp matters at all.