Data Science Interview Question at Airbnb
Find the price of the most expensive beach properties for each city
Hello everyone, on this occasion I would like to share insights about solving problems from the Interview Question for the role data science at the Airbnb. In this problem, will be solved using the python programming language.
So the task we should “Find the price of the most expensive beach properties for each city. Output the result along with the city name”.
There is a table named airbnb_search_details with 20 columns and 160 rows.
# Import your libraries
import pandas as pd# Start writing code
airbnb_search_details.info()
Next we check how the information of the data are by doing the command as below.
airbnb_search_details.head()
Next we look for the data row that contains the word “beach” in the amenities column by filtering it like the code shown below.
df = airbnb_search_details
df['beach'] = df[df['amenities'].str.contains('beach') == True]
Then we do a grouping based on the name of the city (city) and find the largest value using the max ().
df.groupby('city')['price'].max().reset_index()
Another way to use the query command in PostgreSQL is as below
SELECT
city, max(price)
FROM airbnb_search_details
WHERE
amenities ILIKE '%beach%'
GROUP BY
city