Challenge - 5 Problems
Date Range Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of daily date range creation
What is the output of the following code snippet that creates a daily date range?
Pandas
import pandas as pd dates = pd.date_range(start='2024-01-01', end='2024-01-05') print(dates)
Attempts:
2 left
💡 Hint
Check how pandas.date_range includes both start and end dates by default with daily frequency.
✗ Incorrect
The pd.date_range function with start and end dates and default daily frequency includes every day from start to end inclusive.
❓ data_output
intermediate1:30remaining
Number of periods in a weekly date range
How many dates are generated by this weekly date range starting on 2024-01-01 for 4 periods?
Pandas
import pandas as pd dates = pd.date_range(start='2024-01-01', periods=4, freq='W') print(len(dates))
Attempts:
2 left
💡 Hint
The periods parameter controls how many dates are generated.
✗ Incorrect
The periods=4 means exactly 4 dates are generated at weekly intervals starting from the start date.
🔧 Debug
advanced2:00remaining
Identify the error in this date_range code
What error does this code produce and why?
import pandas as pd
dates = pd.date_range(start='2024-01-01', end='2024-01-10', freq='2X')
print(dates)
Pandas
import pandas as pd dates = pd.date_range(start='2024-01-01', end='2024-01-10', freq='2X') print(dates)
Attempts:
2 left
💡 Hint
Check if '2X' is a valid frequency alias in pandas.
✗ Incorrect
The frequency alias '2X' is invalid in pandas, causing a ValueError about invalid frequency.
🚀 Application
advanced2:00remaining
Create a date range for business days excluding weekends
Which code snippet correctly creates a date range of 5 business days starting from 2024-01-01?
Attempts:
2 left
💡 Hint
Business day frequency is represented by 'B' in pandas.
✗ Incorrect
Using freq='B' generates dates only on business days (Monday to Friday). Using periods=5 gives exactly 5 business days.
🧠 Conceptual
expert2:30remaining
Understanding the effect of 'closed' parameter in date_range
Given the code below, which dates are included in the resulting date range?
import pandas as pd
dates = pd.date_range(start='2024-01-01', end='2024-01-05', closed='left')
print(dates)
Pandas
import pandas as pd dates = pd.date_range(start='2024-01-01', end='2024-01-05', closed='left') print(dates)
Attempts:
2 left
💡 Hint
The 'closed' parameter controls which endpoint is excluded from the range.
✗ Incorrect
With closed='left', the start date is excluded but the end date is included, so dates from 2024-01-02 to 2024-01-05 are included.