![](/img/trans.png)
[英]How can I get the average of the 3rd to 7th highest selection from three pandas columns?
[英]How to get the every 3rd date starting from the 0th one
我有以下數據:
myList ['2016-01-01', '2016-02-05', '2016-03-04', '2016-04-01',
'2016-05-06', '2016-06-03', '2016-07-01', '2016-08-05',
'2016-09-02', '2016-10-07', '2016-11-04', '2016-12-02',
'2017-01-06', '2017-02-03', '2017-03-03', '2017-04-07']
我需要從第 0 個日期開始獲取每 3 個日期:
['2016-01-01', '2016-04-01', '2016-07-01', ...]
我怎樣才能在一行代碼中做到這一點?
當然我可以做一個for循環:
selected_dates = []
counter = 0
for d in dates:
if counter >= 3:
counter = 0
# add a date
但是有沒有更優雅的解決方案?
是的,確實有:
dates[0::3]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.