2
我正在尋找一種方法來按星期幾和/或選定日期篩選多索引數據框。假設我需要如何篩選多索引數據框上的日期
- 查詢到
select only mondays
; - 另一個查詢,其中我想
select all days except monday and friday
; - 第三個查詢選擇日期輸入列表中的數據,如
select all dates in ['2015-05-14', '2015-05-21', '2015-05-22']
; - 最後,查詢結合了基於星期幾和日期列表的選擇,如
select all dates in ['2015-05-14', '2015-05-21', '2015-05-22'] and thursdays
。
這是怎麼回事?
Col1 Col2 Col3 Col4
Date Two
2015-05-14 10 81.370003 6.11282 39.753 44.950001
11 80.419998 6.03380 39.289 44.750000
C3 80.879997 6.00746 41.249 44.360001
2015-05-19 3 80.629997 6.10465 41.047 40.980000
S9 80.550003 6.14370 41.636 42.790001
2015-05-21 19 80.480003 6.16096 42.137 43.680000
2015-05-22 C3 80.540001 6.13916 42.179 43.490002
酷!讓我再問你一些事情:如果我還想選擇輸入日期列表中的數據,該怎麼辦?喜歡,選擇['2015-05-14','2015-05-21','2015-05-22']中的所有日期;以及更多,如果我想結合選擇基於星期幾和日期列表?我可以編輯問題。謝謝! – Bella
您可以使用或條件'np.in1d(dayofweek,[1,2,3,5,6])|例如np.in1d(datestr,['2017-01-01','2017-04-02'])'。您可能需要將日期轉換爲第二個表達式中的字符串。 – Psidom