df= fact_orders_grubhub_python.merge(dim_delivery_person_grubhub_python, on='Delivery_person_ID')
# Use the `groupby` and `agg` functions to compute the average age and rating for each city_type
df = df.groupby('city_type').agg({
'Delivery_person_Age': 'mean',
'Delivery_person_Ratings': 'mean'
}).reset_index()
# Use the `round` function to round the age and rating columns to 2 decimal places
df['Delivery_person_Age'] = df['Delivery_person_Age'].round(2)
df['Delivery_person_Ratings'] = df['Delivery_person_Ratings'].round(2)
# Rename the columns to match the names in the SQL query
df.rename(columns={
'Delivery_person_Age': 'avg_age',
'Delivery_person_Ratings': 'avg_rating'
}, inplace=True)
print(df.head(5))
No comments:
Post a Comment