Time series data has a special order and depends on time. Which reason best explains why it needs special handling?
Think about how the sequence of data points matters in time series.
Time series data is ordered by time, so the sequence affects trends and patterns. Ignoring order can lead to wrong conclusions.
Look at the plot generated by this code. What pattern does it show?
import matplotlib.pyplot as plt import pandas as pd import numpy as np dates = pd.date_range('20230101', periods=10) data = np.arange(10) + np.sin(np.arange(10)) plt.plot(dates, data) plt.title('Simple Time Series') plt.show()
Look at how the values change over time with a smooth trend and small ups and downs.
The data increases steadily but has small sine wave fluctuations, showing a trend with seasonality.
Given daily data, what is the result of resampling it to weekly sums?
import pandas as pd import numpy as np dates = pd.date_range('2024-01-01', periods=10) data = pd.Series(np.ones(10), index=dates) weekly_sum = data.resample('W').sum() print(weekly_sum)
Check how weekly resampling sums daily values ending on Sunday.
Resampling with 'W' sums values for each week ending Sunday. First week has 7 days, second has 3 days.
This code plots data but the x-axis dates look wrong. What is the cause?
import matplotlib.pyplot as plt import pandas as pd dates = ['2023-01-01', '2023-01-02', '2023-01-03'] data = [1, 2, 3] plt.plot(dates, data) plt.show()
Check the type of the dates variable and how matplotlib handles it.
Matplotlib needs datetime objects for proper date axis. Strings are treated as labels, causing wrong axis.
You have daily sales data but some dates are missing. Which approach correctly fills missing dates with zero sales?
import pandas as pd dates = pd.to_datetime(['2023-01-01', '2023-01-03', '2023-01-04']) sales = pd.Series([100, 150, 200], index=dates) # Fill missing dates with zero sales filled_sales = sales.asfreq('D', fill_value=0) print(filled_sales)
Think about how to add missing dates with zero values, not just filling existing NaNs.
Using asfreq('D', fill_value=0) creates a daily index filling missing dates with zero.