サーチ…
時系列の作成
単純な時系列を作成する方法は次のとおりです。
import pandas as pd
import numpy as np
# The number of sample to generate
nb_sample = 100
# Seeding to obtain a reproductible dataset
np.random.seed(0)
se = pd.Series(np.random.randint(0, 100, nb_sample),
                  index = pd.date_range(start = pd.to_datetime('2016-09-24'),
                                        periods = nb_sample, freq='D'))
se.head(2)
# 2016-09-24    44
# 2016-09-25    47
se.tail(2)
# 2016-12-31    85
# 2017-01-01    48
部分文字列索引付け
時系列をサブセット化するための非常に便利な方法は、 部分文字列索引付けを使用することです。明確な構文で日付の範囲を選択することができます。
データの取得
データセットの作成時系列の例で使用しています
頭と尾を表示して境界を表示する
se.head(2).append(se.tail(2))
# 2016-09-24    44
# 2016-09-25    47
# 2016-12-31    85
# 2017-01-01    48
サブセッティング
今、私たちは、年、月、日で非常に直感的にサブセット化することができます。
年まで
se['2017']
# 2017-01-01    48
月ごと
se['2017-01']
# 2017-01-01    48
日ごとに
se['2017-01-01']
# 48
あなたの必要に応じて、年、月、日の範囲で。
se['2016-12-31':'2017-01-01']
# 2016-12-31    85
# 2017-01-01    48
 pandasは、 afterとbeforeパラメータを使って、この使い方に専用のtruncate関数も提供していますが、それはあまり明確ではないと思います。 
se.truncate(before='2017')
# 2017-01-01    48
se.truncate(before='2016-12-30', after='2016-12-31')
# 2016-12-30    13
# 2016-12-31    85
Modified text is an extract of the original Stack Overflow Documentation
        ライセンスを受けた CC BY-SA 3.0
        所属していない Stack Overflow