The following line produces a date vector with a weekly frequency, using the sundays as the 'reported' date for each week.
date_vector=pd.date_range(start='12/31/2006', end='01/31/2007', freq='W')
The outcome is as follows:
[Timestamp('2006-12-31 00:00:00', freq='W-SUN'), Timestamp('2007-01-07 00:00:00', freq='W-SUN'), Timestamp('2007-01-14 00:00:00', freq='W-SUN'), Timestamp('2007-01-21 00:00:00', freq='W-SUN'), Timestamp('2007-01-28 00:00:00', freq='W-SUN')]
As you can tell, each date reported is for a sunday. But I want it to be for every friday (the end of the business week). Is something like that possible in pandas? I searched for the different frequencies available in the Pandas documentation for date_range (here) but couldn't find anything like that.
My proposed solution would be a list comprehension in which for each element of this list I'd figure out if its sunday, and if that's the case apply a timedelta of -2 to lag it to fridays. But not sure if that's the most efficient out there and I wanted to see if anyone here could suggest something better.
Thanks for your valuable time!
You can using freq='W-Fri'
date_vector=pd.date_range(start='12/31/2006', end='01/31/2007', freq='W-Fri')
date_vector
Out[1228]: DatetimeIndex(['2007-01-05', '2007-01-12', '2007-01-19', '2007-01-26'], dtype='datetime64[ns]', freq='W-FRI')