I am looking for a solution to get from a date (timestamp), the last date of the previous year. For Example
date = '2021-01-31' or '2021-04-25' . i expect '2020-12-31'
import pandas as pd
report_date = '2021-01-31'
report_date_tsmp = pd.Timestamp(report_date)
thanks for solutions!
Quick and dirty:
pd.Timestamp(f'12-31-{report_date_tsmp.year - 1}')
Less dirty with offset:
report_date_tsmp - pd.offsets.YearEnd()
Output:
Timestamp('2020-12-31 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