Average rating by vehicle type

joins

Average rating by vehicle type

Uber Pandas Interview Question

Uber's rider experience team wants to know whether riders rate some ride options more highly than others. Riders do not always leave a rating.

Using the rides and drivers DataFrames, find the average rider rating for each vehicle_type, as avg_rating, rounded to 2 decimal places. Leave out rides with no rating. Sort the rows by avg_rating, highest first. Assign the answer to result.

Asked of

  • Data Analyst
  • Product Analyst
  • Data Scientist
  • Analytics Engineer
  • ML Engineer

ridesDataFrame20 rows

Column NameType
ride_idint64
driver_idint64
citystr
requested_atstr
farefloat64
ratingfloat64

driversDataFrame10 rows

Column NameType
driver_idint64
driver_namestr
vehicle_typestr
joined_datestr

ridesExample Input

ride_iddriver_idcityrequested_atfarerating
7001301Chicago2024-06-03 08:12:0018.45
7002302Chicago2024-06-03 08:40:0032.14
7003303Austin2024-06-03 09:05:0054.755
7004304Austin2024-06-03 09:30:0012.9NULL
7005301Chicago2024-06-03 11:15:0021.64
7006305Seattle2024-06-03 12:02:0087.25
7007306Seattle2024-06-03 12:45:0016.33
7008302Chicago2024-06-03 13:20:0027.8NULL
7009307Austin2024-06-03 14:10:00414
7010303Austin2024-06-03 15:35:0063.255
7011304Austin2024-06-03 16:05:0014.22
7012308Seattle2024-06-03 17:40:0095.64
7013305Seattle2024-06-03 18:15:0076.45
7014306Seattle2024-06-03 18:50:0019.94

driversExample Input

driver_iddriver_namevehicle_typejoined_date
301Maya PatelUberX2021-04-12
302Luis RomeroComfort2020-09-01
303Grace KimUberXL2022-01-20
304Omar HaddadUberX2023-03-08
305Elena PetrovaBlack2019-11-15
306Sam OkoyeUberX2022-07-30
307Priya IyerComfort2021-12-05
308Noah FischerBlack2020-05-22

Example Output

vehicle_typeavg_rating
UberXL5
Black4.67
Comfort4
UberX3.6

Explanation

In the example, UberXL's two rides were both rated 5, so its average is 5.0. Black's three rides were rated 5, 4 and 5, which averages 4.67. Comfort had ratings of 4 and 4 plus one ride with no rating, which is left out rather than counted as 0, so Comfort averages 4.0.

The example above is a small slice of the data. Your code runs against the full DataFrames.