What is the purpose of pd.date_range()?

0377

The pd.date_range() function in Pandas is used to generate a range of dates and times. It creates a sequence of dates with a specified frequency, which can be useful for creating time series data or setting a datetime index for a DataFrame or Series.

Here’s a basic example:

import pandas as pd

# Generate a range of dates
date_range = pd.date_range(start='2021-01-01', periods=5, freq='D')
print(date_range)

In this example, pd.date_range() creates a range of 5 consecutive dates starting from January 1, 2021, with a daily frequency (freq='D').

0 Comments

no data
Be the first to share your comment!