開始使用免費開始

使用彙總函式

當資料表的粒度比分析所需更細時,先用 SQL 彙總函式把資料彙整後再匯入,會更合理。例如,若你有每月的淹水事件次數,但降雨量是每日資料,你可以決定依月份將降雨量使用 SUM 加總。

weather 資料表包含 4 個月的每日觀測。在這個練習中,你會用 MAXMINSUM 依月份彙整天氣資料。

已載入 pandaspd,並已建立資料庫引擎 engine

本練習屬於課程

使用 pandas 的精實資料導入

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# 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)
編輯並執行程式碼