Recall & Review
beginner
What does the pandas function
date_range do?It creates a sequence of dates between a start and end date or for a specified number of periods, useful for time series data.
Click to reveal answer
beginner
How do you create a date range starting from '2024-01-01' for 5 days using
date_range?Use
pd.date_range(start='2024-01-01', periods=5) to get 5 consecutive dates starting from January 1, 2024.Click to reveal answer
beginner
What parameter in
date_range controls the frequency of dates generated?The
freq parameter controls the frequency, like daily ('D'), monthly ('M'), or hourly ('H').Click to reveal answer
intermediate
How can you create a date range from '2024-01-01' to '2024-01-10' with a frequency of 2 days?
Use
pd.date_range(start='2024-01-01', end='2024-01-10', freq='2D') to get dates every 2 days.Click to reveal answer
beginner
What type of object does
date_range return?It returns a
DatetimeIndex, which is like a list of timestamps that pandas can use for indexing time series data.Click to reveal answer
Which parameter do you use to specify the number of dates in
date_range?✗ Incorrect
The
periods parameter sets how many dates to generate.What is the default frequency if you do not specify
freq in date_range?✗ Incorrect
The default frequency is daily ('D').
How do you create a date range that ends on '2024-12-31' starting from '2024-12-25'?
✗ Incorrect
You specify both start and end dates to create the range.
What will
pd.date_range(start='2024-01-01', periods=3, freq='M') produce?✗ Incorrect
Frequency 'M' means month end, so dates are Jan 31, Feb 29 (leap year), Mar 31.
Which object type is returned by
pd.date_range?✗ Incorrect
date_range returns a DatetimeIndex object.Explain how to create a date range for 10 days starting from March 1, 2024, and how to change the frequency to weekly.
Think about start date, number of periods, and freq parameter.
You got /3 concepts.
Describe the difference between specifying
end vs periods in date_range.Consider how the length of the date range is controlled.
You got /3 concepts.