Python Interview Prep/Clean the Trip Log
Uber logo

Clean the Trip Log

Uber·medium·pandas·About 25 min in the room

trips came out of three regional systems and needs cleaning. Its columns are trip_id, city, fare and status. City names arrive in mixed case with stray spaces, fares arrive as text ("£12.50", "9", "£1,050.00", or empty), and some trips were exported twice with the same trip_id. Keep one row per trip_id, keep only completed trips (the status in any case, with stray spaces), and treat a missing fare as 0. Return result with the columns city (lower case, trimmed) and total_fare (rounded to 2), one row per city, from the highest total down.

The data

trips12 rows
trip_idint64cityobjectfareobjectstatusobject
1001 london£12.50completed
1002LONDON9Completed
1003Manchester £31.20completed
1003Manchester £31.20completed
1004manchestercompleted
1005London£1,050.00completed
and 6 more rows

Target output

citytotal_fare
london1071.5
manchester31.2
leeds29.5
bristol11

What this question tests

Tests data cleaning as it happens on the job: text that should be numbers, names that should match, rows that were exported twice. Interviewers use it to see whether you inspect the data before aggregating it, because every one of these problems changes the totals without raising an error.

More Python interview questions

  • Weeks at Number One · Spotify · easy
  • The Salary Gap · LinkedIn · easy
  • Month-over-Month Revenue · Amazon · medium
  • Back Within a Week · Amazon · medium
Python
Shift+EnterPython is starting in your browser...
Output

Starting Python...