Reputation: 3564
I want to divide the date range starting from 1st July to 1st August, in weekly basis. But I want it to start from 1st day of the month.
I am using pd.date_range('2015-07-01', '2015-08-01', freq='W' )
But I am getting
DatetimeIndex(['2015-07-05', '2015-07-12', '2015-07-19', '2015-07-26'], dtype='datetime64[ns]', freq='W-SUN')
I want this to be done from 2015-07-01
. I know I can use timedelta
or find the start day of the month and use W-WED
. But is there any other shortcut to do the same using date_range
of pandas
?
I have checked http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases, but could not come up with anything useful.
Any help is appreciated. Thanks in advance.
Upvotes: 1
Views: 1248
Reputation: 173
I would suggest using the frequency of 7 days instead of a week, so that you will start at the first day of the month rather than the first day of the week
pd.date_range('2015-07-01', '2015-08-01', freq='7d')
EDIT
To clarify, it is not strictly the first day of the month, but the first day you provide. But in your example those two are the same
Upvotes: 4