Get startedGet started for free

Working with aggregate functions

If a table contains data with higher granularity than is needed for an analysis, it can make sense to summarize the data with SQL aggregate functions before importing it. For example, if you have data of flood event counts by month but precipitation data by day, you may decide to SUM precipitation by month.

The weather table contains daily readings for four months. In this exercise, you'll practice summarizing weather by month with the MAX, MIN, and SUM functions.

pandas has been loaded as pd, and a database engine, engine, has been created.

This exercise is part of the course

Streamlined Data Ingestion with pandas

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create a query to get month and max tmax by month
query = """
SELECT ____, 
       ____
  FROM ____ 
  ____ ____;"""

# Get dataframe of monthly weather stats
weather_by_month = pd.read_sql(query, engine)

# View weather stats by month
print(weather_by_month)
Edit and Run Code