Date Ranges
date_range builds a regular sequence of dates. freq sets the step, such as D for days or MS for month starts.
Example
import pandas as pd
import numpy as np
r = pd.date_range('2024-01-01', periods=4, freq='D')
print(r.strftime('%Y-%m-%d').tolist())
print(pd.date_range('2024-01-31', periods=3, freq='ME').strftime('%b').tolist())Result
['2024-01-01', '2024-01-02', '2024-01-03', '2024-01-04'] ['Jan', 'Feb', 'Mar']
Exercise
Make 3 days.
pd.date_range("2024-01-01", =3)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.