上傳 2 月的彙整報表
在上一個練習中,Sam 從原始資料的 bucket 下載了該月份的所有檔案。
接著她把這些檔案合併成一個 DataFrame,彙整了該月份的所有請求與請求類型。
她把這個 DataFrame 存在變數 all_reqs,並使用 pandas 的 groupby 功能,依服務名稱計數,產生新的 DataFrame agg_df:
| service_name | count | |
|---|---|---|
| 0 | 72 Hour Violation | 2910 |
| 1 | Chain Link Fence Repair | 90 |
| 2 | Collections Truck Spill | 30 |
| 3 | Container Left Out | 120 |
| 4 | Dead Animal | 360 |
她已經在變數 s3 中建立了 boto3 的 S3 用戶端。
請協助她發布本月的請求統計。
將 agg_df 輸出為 CSV 與 HTML 檔案,並以上傳至 S3,設為公開存取。
本練習屬於課程
Python 中的 AWS Boto 入門
練習說明
- 將
agg_df另存為 CSV 與 HTML 版本,分別命名為'feb_final_report.csv'與'feb_final_report.html'。 - 將兩個版本上傳到
gid-reportsbucket,並將權限設為可公開讀取。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Write agg_df to a CSV and HTML file with no border
agg_df.____('./____')
agg_df.____('./____', border=0)
# Upload the generated CSV to the gid-reports bucket
s3.____(Filename='./feb_final_report.csv',
Key='2019/feb/final_report.html', Bucket='gid-reports',
____ = {'ACL': '____'})
# Upload the generated HTML to the gid-reports bucket
s3.upload_file(Filename='./feb_final_report.html',
Key='2019/feb/final_report.html', Bucket='gid-reports',
____ = {'ContentType': '____',
'____': '____'})