# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="b0CqLhJh2s7b"
# 作業目標:<br>
# 1. 熟悉時間序列資料運算
# 2. 敘述統計量應用在時間序列資料上
#
#

# + [markdown] id="RVN7uazcbsex"
# 作業重點:<br>
# 1. 須注意時間的間隔問題，例如:一周、一年...
# 2. 敘述統計量一樣可以應用在時間序列資料上

# + [markdown] id="xiYCa02a2vRm"
# 題目 : 運下列時間序列資料做運算<br>
#
#
# ```
# index = pd.date_range("1/1/2019", periods=20, freq='D')
# series = pd.Series(range(20), index=index)
# ```
#
#
# 1. 將所有轉為周資料
# 2. 將周資料的值取平均

# + colab={"base_uri": "https://localhost:8080/"} id="1MMZgjdd2un2" executionInfo={"status": "ok", "timestamp": 1608480673166, "user_tz": -480, "elapsed": 835, "user": {"displayName": "\u732e\u7ae4\u9ec3", "photoUrl": "", "userId": "07529243043474362942"}} outputId="ad3a2361-9c71-47af-bef2-ffc0b810aa2d"
import numpy as np
import pandas as pd
index = pd.date_range('1/1/2019', periods=20, freq='D')
series = pd.Series(range(20), index=index)
series

# + colab={"base_uri": "https://localhost:8080/"} id="tSR16Mk06ciP" executionInfo={"status": "ok", "timestamp": 1608480678121, "user_tz": -480, "elapsed": 733, "user": {"displayName": "\u732e\u7ae4\u9ec3", "photoUrl": "", "userId": "07529243043474362942"}} outputId="821ccd88-172e-4e27-8479-d767be484358"
#1. 將所有轉為周資料
series.to_period('W')

# + colab={"base_uri": "https://localhost:8080/"} id="9hQbh1yU5ZRf" executionInfo={"status": "ok", "timestamp": 1608480831150, "user_tz": -480, "elapsed": 831, "user": {"displayName": "\u732e\u7ae4\u9ec3", "photoUrl": "", "userId": "07529243043474362942"}} outputId="3ea574e2-ee45-4fbd-f228-33d4bfa87726"
#2. 將周資料的值取平均
series.resample('W').mean()

StarcoderdataJupyterScriptsDedupFiltered