python - first date of week greater than x -
i first monday in july greater july 10th list of dates, , wondering if there's elegant solution avoids loops/list comprehension. here code far gives july mondays greater 10th:
import pandas pd last_date = '08-jul-2016' monday2_dates=pd.date_range('1-jan-1999',last_date, freq='w-mon') g1=pd.dataframe(1.0, columns=['dummy'], index=monday2_dates) g1=g1.loc[(g1.index.month==7) & (g1.index.day>=10)]
iiuc can way:
get list of 2nd mondays within specified date range
in [116]: rng = pd.date_range('1-jan-1999',last_date, freq='wom-2mon')
filter them have in july day >= 10
in [117]: rng = rng[(rng.month==7) & (rng.day >= 10)]
create corresponding df
in [118]: df = pd.dataframe({'dummy':[1] * len(rng)}, index=rng) in [119]: df out[119]: dummy 1999-07-12 1 2000-07-10 1 2003-07-14 1 2004-07-12 1 2005-07-11 1 2006-07-10 1 2008-07-14 1 2009-07-13 1 2010-07-12 1 2011-07-11 1 2014-07-14 1 2015-07-13 1
Comments
Post a Comment