0
0
Pandasdata~20 mins

Time series analysis patterns in Pandas - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Time Series Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of resampling time series data

What is the output of this code that resamples daily data to monthly sums?

Pandas
import pandas as pd

dates = pd.date_range('2023-01-01', periods=6, freq='D')
data = pd.Series([1, 2, 3, 4, 5, 6], index=dates)
result = data.resample('M').sum()
print(result)
A
2023-01-01    21
Freq: M, dtype: int64
B
2023-01-31    6
Freq: M, dtype: int64
C
2023-01-31    21
Freq: M, dtype: int64
D
2023-01-06    21
Freq: D, dtype: int64
Attempts:
2 left
💡 Hint

Monthly resampling sums all daily values in January.

data_output
intermediate
2:00remaining
Number of missing values after forward fill

Given this time series with missing values, how many missing values remain after forward filling?

Pandas
import pandas as pd
import numpy as np

dates = pd.date_range('2023-01-01', periods=5, freq='D')
data = pd.Series([np.nan, 2, np.nan, 4, np.nan], index=dates)
filled = data.ffill()
missing_count = filled.isna().sum()
print(missing_count)
A1
B0
C2
D3
Attempts:
2 left
💡 Hint

Forward fill replaces NaN with previous non-NaN value. The first NaN has no previous value.

visualization
advanced
3:00remaining
Identifying seasonality in time series plot

Which plot best shows clear seasonality in monthly sales data?

Pandas
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(0)
dates = pd.date_range('2022-01-01', periods=24, freq='M')
sales = 10 + 5 * np.sin(2 * np.pi * dates.month / 12) + np.random.normal(0, 1, 24)
data = pd.Series(sales, index=dates)
plt.plot(data.index, data.values)
plt.title('Monthly Sales with Seasonality')
plt.xlabel('Date')
plt.ylabel('Sales')
plt.show()
AA histogram of sales values
BA scatter plot with random points and no pattern
CA bar chart with steadily increasing values
DA line plot showing repeating peaks every 12 months
Attempts:
2 left
💡 Hint

Seasonality means repeating patterns at regular intervals.

🧠 Conceptual
advanced
1:30remaining
Effect of differencing on time series data

What is the main effect of applying first-order differencing to a time series?

AIt increases the variance of the series
BIt removes trend and stabilizes the mean
CIt smooths the series by averaging values
DIt adds seasonality to the series
Attempts:
2 left
💡 Hint

Think about what subtracting consecutive values does to a trending series.

🔧 Debug
expert
2:00remaining
Error raised by incorrect time series indexing

What error does this code raise when trying to access a time series value?

Pandas
import pandas as pd

dates = pd.date_range('2023-01-01', periods=3, freq='D')
data = pd.Series([10, 20, 30], index=dates)
value = data['2023-01-04']
print(value)
AKeyError
BIndexError
CTypeError
DValueError
Attempts:
2 left
💡 Hint

Check if the date key exists in the index.