CHAPTER 18
Beginner
Working with Dates and Time Series
Updated: May 18, 2026
5 min read
# CHAPTER 18
Working with Dates and Time Series
1. Chapter Introduction
Time series data — stock prices, sales trends, sensor readings — is among the most valuable data in business. Pandas has world-class datetime support: parsing, filtering, resampling, rolling windows, and time zone handling.2. Parsing Dates
python
3. DateTime Accessor — dt
python
4. Date Filtering
python
5. Resampling
python
6. Rolling Windows
python
7. Common Mistakes
-
Strings not parsed as dates: After
readcsv, date columns are strings by default. Always useparsedates=['col']orpd.todatetime(df['col']).
-
resamplerequires DatetimeIndex: Set the date column as index withdf.setindex('Date')before resampling.
8. MCQs
Question 1
pd.todatetime() converts?
Question 2
df['Date'].dt.month extracts?
Question 3
df['2024-01'] with DatetimeIndex?
Question 4
resample('W').sum() aggregates?
Question 5
rolling(7).mean() computes?
Question 6
pctchange() returns?
Question 7
shift(1) does?
Question 8
expanding().sum() computes?
Question 9
dt.dayofweek == 5 means?
Question 10
diff() on time series computes?
9. Interview Questions
- Q: How do you resample daily data to monthly totals in Pandas?
-
Q: What is the difference between
rolling()andexpanding()?
10. Summary
Pandas datetime support:to_datetime() for parsing, .dt accessor for component extraction, date-based filtering with DatetimeIndex, resample() for frequency conversion, and rolling()/expanding() for moving window analytics. Time series analysis is Pandas' strongest domain.