Complete the code to group the DataFrame by 'city' and calculate the mean of 'temperature'.
grouped = df.groupby([1])['temperature'].mean()
The groupby function groups data by the specified column. Here, we group by 'city' to find the average temperature per city.
Complete the code to group the DataFrame by both 'city' and 'date' columns.
grouped = df.groupby([1]).sum()
Grouping by multiple columns requires a list of column names. Here, we group by both 'city' and 'date' to aggregate data for each city on each date.
Fix the error in the code to group by 'city' and 'date' and calculate the mean temperature.
result = df.groupby([1]).mean()['temperature']
The groupby method expects a list of column names to group by multiple columns. Using a list like ['city', 'date'] is correct.
Fill both blanks to create a dictionary comprehension that maps each city to the count of dates where temperature is above 20.
counts = {city: df[(df['city'] == city) & (df['temperature'] [1] 20)]['date'].[2]() for city in df['city'].unique()}The condition checks if temperature is greater than 20. Then count() counts the number of dates matching the condition for each city.
Fill all three blanks to create a dictionary comprehension that maps each city to the average humidity on days when temperature is below 15.
avg_humidity = {city: df[(df['city'] == city) & (df['temperature'] [1] 15)]['[2]'].[3]() for city in df['city'].unique()}The condition checks if temperature is less than 15. Then the mean humidity is calculated for those days per city.