Pandas: Business quarterly begin and end dates of a specified year
Pandas Time Series: Exercise-22 with Solution
Write a Pandas program to find the all the business quarterly begin and end dates of a specified year.
Sample Solution:
Python Code :
import pandas as pd
q_start_dates = pd.date_range('2020-01-01', '2020-12-31', freq='BQS-JUN')
q_end_dates = pd.date_range('2020-01-01', '2020-12-31', freq='BQ-JUN')
print("All the business quarterly begin dates of 2020:")
print(q_start_dates.values)
print("\nAll the business quarterly end dates of 2020:")
print(q_end_dates.values)
Sample Output:
All the business quarterly begin dates of 2020: ['2020-03-02T00:00:00.000000000' '2020-06-01T00:00:00.000000000' '2020-09-01T00:00:00.000000000' '2020-12-01T00:00:00.000000000'] All the business quarterly end dates of 2020: ['2020-03-31T00:00:00.000000000' '2020-06-30T00:00:00.000000000' '2020-09-30T00:00:00.000000000' '2020-12-31T00:00:00.000000000']
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Pandas program to calculate all Thursdays between two given days.
Next: Write a Pandas program to generate sequences of fixed-frequency dates and time spans intervals.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/python-exercises/pandas/time-series/pandas-time-series-exercise-22.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics