cswork / libraryOpen practice workspace

Coding questions · Rbcroyalbank

Explain pandas and SQL basics

This question evaluates familiarity with pandas data structures (Series vs DataFrame), SQL filtering semantics (WHERE vs HAVING), and practical SQL aggregation for detecting duplicate records, assessing competencies in data manipulation, aggregation, and basic data quality checks.

You are interviewing for a Data Engineer co-op/intern role. Answer the following short technical questions.

Python / pandas:

  1. What is the difference between a pandas Series and a pandas DataFrame? Give one practical example of when you would use each.

SQL concepts: 2. What is the difference between WHERE and HAVING in SQL, and when should each be used?

SQL query task: 3. You have a table:

customer_events

  • event_id BIGINT
  • customer_email STRING
  • source_system STRING
  • created_at TIMESTAMP

Assume created_at is stored in UTC. Write a SQL query to find duplicate customer_email values in the table. A duplicate means the same customer_email appears more than once in the full table. Return these output columns:

  • customer_email
  • duplicate_count

Only include emails that appear more than once.

Explain pandas and SQL basics

Table customer_events

columntypeconstraints
event_idBIGINT
customer_emailVARCHAR(254)
source_systemVARCHAR(50)
created_atTIMESTAMP

Sample data:

created_atcustomer_emailevent_idsource_system
2023-07-01 10:15:00alice@example.com1web
2023-07-01 10:16:00bob@example.com2mobile
2023-07-02 11:30:00alice@example.com3mobile
2023-07-03 12:00:00charlie@example.com4web
2023-07-03 12:10:00diana@example.com5partner
2023-07-04 13:00:00bob@example.com6web
2023-07-05 09:25:00bob@example.com7partner
2023-07-06 15:45:00eve@example.com8web
2023-07-06 16:00:00frank@example.com9mobile
2023-07-07 08:10:00alice@example.com10partner
2023-07-07 10:05:00diana@example.com11web

Expected output

All customer_email values that occur more than once, with the number of occurrences for each email.

customer_emailduplicate_count
alice@example.com3
bob@example.com3
diana@example.com2

Hints

  1. Aggregate by customer_email and count rows per email.
  2. Use HAVING to filter aggregated results to counts greater than 1.
  3. Add ORDER BY for deterministic output matching the sample.