In this article, we will print all the dates starting from the given date for n number days. It can be done using the pandas.date_range() function. This function is used to get a fixed frequency DatetimeIndex.
Syntax: pandas.date_range(start=None, end=None, periods=None, freq=None, tz=None, normalize=False, name=None, closed=None, **kwargs)
Approach:
- Import pandas module
- Create a parameter function for computing the Date series between starting date and periods.
- Generate sequences of dates between starting and periods with pandas.date_range() within the function
- Store into the pandas series within the function
- Return the pandas series.
Below is the implementation.
Python3
# Importing modules import pandas as pd # creating function def Time_series(date, per): # computing date range with date # and given periods date_series = pd.date_range(date, periods=per) # creating series for date_range Result = pd.Series(date_series) print(Result) # Driver Code # Date in the YYYY-MM-DD format date = "2020-03-01" # Number of times the date is # needed to be printed per = 10Time_series(date, per) |
Output :
0 2020-03-01 1 2020-03-02 2 2020-03-03 3 2020-03-04 4 2020-03-05 5 2020-03-06 6 2020-03-07 7 2020-03-08 8 2020-03-09 9 2020-03-10 dtype: datetime64[ns]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- How to display the days of the week for a particular year using Pandas?
- PyQt5 - Days From Date Calculator
- Python | Pandas TimedeltaIndex.days
- Python | Pandas Timedelta.days
- Count the number of days of a specific month using NumPy
- Python program to find number of days between two given dates
- Extract date from a specified column of a given Pandas DataFrame using Regex
- How to Learn Python in 21 Days?
- Python | Working with date and time using Pandas
- How to sort date in excel using Pandas?
- How to extract date from Excel file using Pandas?
- Extract week number from date in Pandas-Python
- How to remove lines starting with any prefix using Python?
- Python | Get the starting index for all occurrences of given substring
- Python - Filter list elements starting with given Prefix
- Python | Pandas Timestamp.date
- Python | Pandas DatetimeIndex.date
- Python | Pandas Series.dt.date
- Get Month from date in Pandas - Python
- Get month and Year from Date in Pandas - Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

