All our Data Science projects include bite-sized activities to test your knowledge and practice in an environment with constant feedback.
All our activities include solutions with explanations on how they work and why we chose them.
Create a new column called price_per_night that calculates the price per night for each Airbnb listing.
Modify the original DataFrame
df.
Modify the original DataFrame
df.
Add a new row to the DataFrame df at the end with the following details:
new_row_data = {'id': 12345, 'name': 'Cozy Studio Apartment', 'host_id': 67890, 'room_type': 'Entire home/apt',
'price': 150, 'minimum_nights': 3, 'number_of_reviews': 10}
Sort the DataFrame df by the price column in descending order and assign the result to sorted_df.
Create a new column price_eur in the DataFrame df that contains the prices in euros. The conversion rate is 1 US dollar = 0.85 euros.
Create a new column total_nights_price in the DataFrame df that contains the total price of nights for each listing. The total price of nights is calculated by multiplying the minimum_nights column with the price_per_night column.
For splitting a string into a list of words, you can use the split() function. The split() function returns a list of words. To access the first word in the list, you can use indexing. For example, text.split().str[0] returns the first word from the name column.
Create a new column year in the DataFrame df that contains the year information from the last_review column. For example, if the last_review column contains the date 2019-05-21, the year column should contain the value 2019. You can use the dt accessor to access the datetime properties of a column. For example, df['last_review'].dt.year returns the year information from the last_review column.