

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Pandas - Generate dates in a range
To generate dates in a range, use the date _range() method. At first, import the required pandas library with an alias −
import pandas as pd
Now, let’s say you need to generate dates in arrange, therefore for this, mention the date from where you want to begin. Here, we have mentioned 1st June 2021 and period of 60 days −
dates = pd.date_range('6/1/2021', periods=60)
Example
Following is the complete code −
import pandas as pd # generate dates in a range # period is 60 i.e. 60 days from 1st June 2021 dates = pd.date_range('6/1/2021', periods=60) print"Displaying dates in a range...\n",dates
Output
This will produce the following output −
Displaying dates in a range... DatetimeIndex(['2021-06-01', '2021-06-02', '2021-06-03', '2021-06-04', '2021-06-05', '2021-06-06', '2021-06-07', '2021-06-08', '2021-06-09', '2021-06-10', '2021-06-11', '2021-06-12', '2021-06-13', '2021-06-14', '2021-06-15', '2021-06-16', '2021-06-17', '2021-06-18', '2021-06-19', '2021-06-20', '2021-06-21', '2021-06-22', '2021-06-23', '2021-06-24', '2021-06-25', '2021-06-26', '2021-06-27', '2021-06-28', '2021-06-29', '2021-06-30', '2021-07-01', '2021-07-02', '2021-07-03', '2021-07-04', '2021-07-05', '2021-07-06', '2021-07-07', '2021-07-08', '2021-07-09', '2021-07-10', '2021-07-11', '2021-07-12', '2021-07-13', '2021-07-14', '2021-07-15', '2021-07-16', '2021-07-17', '2021-07-18', '2021-07-19', '2021-07-20', '2021-07-21', '2021-07-22', '2021-07-23', '2021-07-24', '2021-07-25', '2021-07-26', '2021-07-27', '2021-07-28', '2021-07-29', '2021-07-30'], dtype='datetime64[ns]', freq='D')
- Related Questions & Answers
- How do I generate days from the range of dates in MySQL?
- Python Pandas - Create RangeIndex from a range object
- Python Pandas – Filter DataFrame between two dates
- Python – How to check missing dates in Pandas
- MySQL select dates in 30-day range?
- Python Generate random numbers within a given range and store in a list
- How can I generate days from the range of dates with the help of MySQL views?
- MySQL date comparison to fetch dates between a given range?
- Python program to generate random numbers within a given range and store in a list?
- Comparing dates in Python
- How to generate random whole numbers in JavaScript in a specific range?
- How can I generate random number in a given range in Android?
- How to plot a kernel density plot of dates in Pandas using Matplotlib?
- Generate n random numbers between a range and pick the greatest in JavaScript
- MySQL query to select all data between range of two dates?
Advertisements