Reputation: 3318
Let say I have a date
import datetime as datetime
mydate = datetime.date(2020, 1, 10)
Now starting from mydate
, I want to create an array of 10
quarters e.g. 2020-Q1, 2020-Q2, ... [total 10 values]
Is there any direct way to achieve this?
In R
, this is pretty straightforward, as I can use seq()
function to generate the same.
Any pointer will be very helpful
Upvotes: 0
Views: 829
Reputation: 101
Be carefaul : datetime.date gives you a date, not a datetime !
You could try something like :
from datetime import datetime, timedelta
mydate = datetime(2020, 1, 10)
quarters = []
for i in range(1, 10):
quarters.append(mydate + timedelta(minutes=15) * i)
Or in one line statement :
quarters = [ mydate + timedelta(minutes=15) * i for i in range(1, 10) ]
pretty straightforward too... ;-)
Upvotes: 0
Reputation: 114048
it doesnt give you the exact format ... but probably close enough
pandas.date_range("2020-01-01",freq="Q",periods=10).to_period('Q')
Upvotes: 1