
Average rating by vehicle type
mediumAverage 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 Name | Type |
|---|---|
| ride_id | int64 |
| driver_id | int64 |
| city | str |
| requested_at | str |
| fare | float64 |
| rating | float64 |
driversDataFrame10 rows
| Column Name | Type |
|---|---|
| driver_id | int64 |
| driver_name | str |
| vehicle_type | str |
| joined_date | str |
ridesExample Input
| ride_id | driver_id | city | requested_at | fare | rating |
|---|---|---|---|---|---|
| 7001 | 301 | Chicago | 2024-06-03 08:12:00 | 18.4 | 5 |
| 7002 | 302 | Chicago | 2024-06-03 08:40:00 | 32.1 | 4 |
| 7003 | 303 | Austin | 2024-06-03 09:05:00 | 54.75 | 5 |
| 7004 | 304 | Austin | 2024-06-03 09:30:00 | 12.9 | NULL |
| 7005 | 301 | Chicago | 2024-06-03 11:15:00 | 21.6 | 4 |
| 7006 | 305 | Seattle | 2024-06-03 12:02:00 | 87.2 | 5 |
| 7007 | 306 | Seattle | 2024-06-03 12:45:00 | 16.3 | 3 |
| 7008 | 302 | Chicago | 2024-06-03 13:20:00 | 27.8 | NULL |
| 7009 | 307 | Austin | 2024-06-03 14:10:00 | 41 | 4 |
| 7010 | 303 | Austin | 2024-06-03 15:35:00 | 63.25 | 5 |
| 7011 | 304 | Austin | 2024-06-03 16:05:00 | 14.2 | 2 |
| 7012 | 308 | Seattle | 2024-06-03 17:40:00 | 95.6 | 4 |
| 7013 | 305 | Seattle | 2024-06-03 18:15:00 | 76.4 | 5 |
| 7014 | 306 | Seattle | 2024-06-03 18:50:00 | 19.9 | 4 |
driversExample Input
| driver_id | driver_name | vehicle_type | joined_date |
|---|---|---|---|
| 301 | Maya Patel | UberX | 2021-04-12 |
| 302 | Luis Romero | Comfort | 2020-09-01 |
| 303 | Grace Kim | UberXL | 2022-01-20 |
| 304 | Omar Haddad | UberX | 2023-03-08 |
| 305 | Elena Petrova | Black | 2019-11-15 |
| 306 | Sam Okoye | UberX | 2022-07-30 |
| 307 | Priya Iyer | Comfort | 2021-12-05 |
| 308 | Noah Fischer | Black | 2020-05-22 |
Example Output
| vehicle_type | avg_rating |
|---|---|
| UberXL | 5 |
| Black | 4.67 |
| Comfort | 4 |
| UberX | 3.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.
Company
Uber
Difficulty
medium
Topic
joins
Language
Pandas
Your code
Loading Python in the background. You can start writing.