2016-04-29 254 views
0

從時間序列中選擇特定單行的最佳方式是什麼?如何在熊貓時間序列中選擇特定季度

我已經得到了一些數據:

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"] 
25468 

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

但是我怎麼選擇這兩個?

我想:

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 

可能有人請解釋給我,好嗎?

回答