I want to get date beginning of quarter of the date
x="2018-02-07"
x=pd.to_datetime(x)
x=x-pd.offsets.QuarterBegin()
print(x)
2017-12-01 00:00:00
Which is wrong and should be "2018-01-01 00:00:00"
Can somebody help me where I am going wrong?
The quarter can simply be obtained through (month - 1) // 3 + 1 .
You can convert to a period and then to a timestamp:
x = pd.to_datetime('2018-02-07')
res = x.to_period('Q').to_timestamp()
print(res)
Timestamp('2018-01-01 00:00:00')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With