How to generate a list of dates in Python

1 min readDataFramePandasDatesData
7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

The easiest method I've seen so far is using the Pandas library.

The method is called pandas.date_range()

Using frequency

# we import the library
import pandas as pd

# We generate the list of dates
list_dates = pd.date_range(start="2021-01-01", end="2021-06-01", freq="D")

We pass the start date and the end date as arguments. As you can see we also pass the frequency, here it will be every day from start date until end date.

You can also pass various frequencies to the freq parameter.

The list is available here.

e.g. One of the most useful is month start.

# We generate the list of dates with a month start frequency
list_dates = pd.date_range(start="2021-01-01", end="2021-06-01", freq="MS")
Using month start as frequency

Or even a 10 days frequency.

# We generate the list of dates with a 10 days frequency
list_dates = pd.date_range(start="2021-01-01", end="2021-06-01", freq="10D")
Using a 10 days frequency

Using periods

Instead of passing the frequency, you can also pass the number of periods you want in between those two dates.

# We generate the list of dates
list_dates = pd.date_range(start="2021-01-01", end="2021-06-01", periods=30)

Here you are !

You know now how to generate a list of dates in Python using Pandas.

7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

Free Newsletter

Master Data Science in Days, Not Months 🚀

Skip the theoretical rabbit holes. Get practical data science skills delivered in bite-sized lessons – Approach used by real data scientist. Not bookworms. 📚

Weekly simple and practical lessons
Access to ready to use code examples
Skip the math, focus on results
Learn while drinking your coffee

By subscribing, you agree to receive our newsletter. You can unsubscribe at any time.