公開日:2019-08-15
最終更新日:2019-08-29
最終更新日:2019-08-29
pd08-0:準備
以下のデータをdataディレクトリに配置したうえで,次のコードを実行しよう.
temperature_otsu.csv:大津の2018年の気温(日時datetime,気温temperature)[1][2]
|
1 2 3 4 |
>>> import numpy as np >>> import pandas as pd >>> >>> df = pd.read_csv('data/temperature_otsu.csv', index_col=0, parse_dates=True) |
- 出展:気象庁ホームページ,2019年8月29日閲覧.
- 気象庁「過去の気象データ」を加工して作成
pd08-1:時系列データのリサンプリング(1)
dfを月単位でリサンプリングしよう.ただし,月ごとの平均気温で集約する.
難易度:★★
| ミッション | 説明 |
|---|---|
| 1 | DataFrame.resample()メソッドを使う. |
| 2 | ruleパラメタを指定する. |
| 3 | DatetimeIndexResampler.mean()メソッドを使う. |
pd08-2:時系列データのリサンプリング(2)
dfを月単位でリサンプリングしよう.ただし,月ごとの最高気温で集約する.
難易度:★★
| ミッション | 説明 |
|---|---|
| 1 | DataFrame.resample()メソッドを使う. |
| 2 | ruleパラメタを指定する. |
| 3 | DatetimeIndexResampler.max()メソッドを使う. |
pd08-3:時系列データのリサンプリング(3)
dfを週単位でリサンプリングしよう.ただし,週ごとの気温中央値で集約する.
難易度:★★
| ミッション | 説明 |
|---|---|
| 1 | DataFrame.resample()メソッドを使う. |
| 2 | ruleパラメタを指定する. |
| 3 | DatetimeIndexResampler.median()メソッドを使う. |
| 4 | リサンプリングしたデータフレームをtsとする. |
pd08-4:時系列データの
DatetimeIndexからPeriodIndexへの変換tsのDatetimeIndexをPeriodIndexに変換しよう.
難易度:★★
| ミッション | 説明 |
|---|---|
| 1 | DataFrame.to_period()メソッドを使う. |
pd08-5:時系列データの可視化
tsを可視化しよう.
|
1 |
>>> import matplotlib.pyplot as plt |
難易度:★★★
| ミッション | 説明 |
|---|---|
| 1 | DataFrame.plot()メソッドを使う. |
| 2 | matplotlib.pyplot.show()関数を使う. |