how to select all the monday form "20150101" till "20150620"?

Chris Angelico rosuav at gmail.com
Mon Jan 5 07:13:07 EST 2015


On Mon, Jan 5, 2015 at 4:49 PM, length power <elearn2014 at gmail.com> wrote:
> import pandas as pd
> rng = pd.date_range("20150101","20150620",freq="D")
> for day in rng:
>    x = pd.to_datetime(day)
>    y = x.timetuple().tm_wday
>    if(y == 0) :print(x.strftime("%Y%m%d"))
>
>
> I have selected all  the monday form "20150101" till "20150620",how to make
> it more simple?

I'm not sure, but I suspect your freq="D" parameter means that it
gives you sequential days. If you start at 20150105 (which is a
Monday), and change that to freq="W" or possibly freq="7D", it might
work just like that. Hint: Have you looked at the pandas
documentation?

ChrisA



More information about the Python-list mailing list