Challenge - 5 Problems
Resampling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this resampling code?
Given a time series with daily data, what is the output after resampling to monthly frequency using sum aggregation?
Pandas
import pandas as pd import numpy as np rng = pd.date_range('2023-01-01', periods=5, freq='D') data = pd.Series([1, 2, 3, 4, 5], index=rng) result = data.resample('M').sum() print(result)
Attempts:
2 left
💡 Hint
Think about what resampling to 'M' (month end) does and how sum aggregates daily values.
✗ Incorrect
Resampling to 'M' groups all days in January and sums their values. The sum of 1+2+3+4+5 is 15, indexed at the last day of January.
❓ data_output
intermediate1:30remaining
How many rows are in the resampled DataFrame?
A DataFrame has hourly data for 2 days. After resampling to daily frequency using mean aggregation, how many rows does the result have?
Pandas
import pandas as pd import numpy as np rng = pd.date_range('2023-01-01', periods=48, freq='H') data = pd.DataFrame({'value': np.arange(48)}, index=rng) result = data.resample('D').mean() print(len(result))
Attempts:
2 left
💡 Hint
Resampling groups data by day. How many days are in 48 hours?
✗ Incorrect
48 hours cover exactly 2 days, so resampling by day results in 2 rows, one for each day.
🔧 Debug
advanced2:00remaining
What error does this resampling code raise?
Identify the error raised by this code snippet:
Pandas
import pandas as pd import numpy as np rng = pd.date_range('2023-01-01', periods=5, freq='D') data = pd.Series(np.arange(5), index=rng) result = data.resample('M').mean() result = result.resample('H').sum()
Attempts:
2 left
💡 Hint
Check the index type after the first resample and if resample supports chaining.
✗ Incorrect
The first resample returns a Series with a DatetimeIndex at month end. Resampling from monthly to hourly is allowed and works without error.
🚀 Application
advanced2:30remaining
Which option produces the correct weekly resampled sum?
Given daily sales data, which code correctly resamples to weekly sums with weeks starting on Monday?
Pandas
import pandas as pd import numpy as np rng = pd.date_range('2023-01-01', periods=14, freq='D') data = pd.Series(np.arange(14), index=rng)
Attempts:
2 left
💡 Hint
Check the alias for weekly resampling starting on Monday.
✗ Incorrect
'W-MON' means weekly frequency with weeks ending on Monday, so sums are grouped accordingly. 'W' defaults to Sunday week end.
🧠 Conceptual
expert3:00remaining
What is the effect of using 'label' and 'closed' parameters in resample?
In pandas resample, what do the 'label' and 'closed' parameters control?
Attempts:
2 left
💡 Hint
Think about how intervals are labeled and which endpoints are included in resampling bins.
✗ Incorrect
'label' sets whether the bin is labeled by its start or end timestamp. 'closed' sets which endpoint (left or right) is included in the bin interval.