2016-04-29 17 views
0

timeseriesから特定の個々の行を選択する最良の方法は何ですか?私はいくつかのデータ持ってパンダの時系列で特定の四半期を選択する方法

indexed.ix["2012-09-30"] 
25468 

indexed.ix["2015-09-30"] 
27038 

しかし、どのように私は両方を選択します:

indexed = df.set_index("Month").resample("Q-MAR", how="sum")['count'] 
indexed 

Month 
2010-12-31  6942 
2011-03-31 23677 
2011-06-30 24131 
2011-09-30 23144 
2011-12-31 22249 
2012-03-31 24216 
2012-06-30 22938 
2012-09-30 25468 
2012-12-31 21733 
2013-03-31 21385 
2013-06-30 23093 
2013-09-30 26206 
2013-12-31 22248 
2014-03-31 20737 
2014-06-30 23384 
2014-09-30 25285 
2014-12-31 22210 
2015-03-31 22627 
2015-06-30 25185 
2015-09-30 27038 
2015-12-31 25352 
2016-03-31 16694 
Freq: Q-MAR, Name: count, dtype: int64 

を、私はこのように、個々のエントリをスライスすることができますか?

は、私が試した:

あまりにも多くのインデクサーのエラーを返します
indexed.ix[["2012-09-30", "2015-09-30"],:] 

...

indexed.ix[["2012-09-30", "2015-09-30"]] 

が戻っ

Month 
2012-09-30 NaN 
2015-09-30 NaN 

をもたらし、私はしませんが理由を理解する

indexed.ix["2012-09-30", "2015-09-30"] 

戻り

25468 

誰かが私にそれを説明してもらえ、してください?

答えて

0

私は、インデックス上でこの答えは有用であることが判明:予想通り、あなたが正しいdtypesを指定した場合、インデックスで pandas, python - how to select specific times in timeseries

indexed[(pd.Index(indexed.index.quarter).isin([3])) & (pd.Index(indexed.index.year).isin([2012,2015]))] 

Month 
2012-09-30 25468 
2015-09-30 27038 
関連する問題