A time series is a pandas DataFrame whose timestamp column becomes the index. This arrangement turns dates into a practical way to select, slice, group, and summarize observations. section 10.8 section 10.17
filename = '../data/wti-daily.csv'
df = pd.read_csv(filename,
parse_dates=['Date'],
index_col=['Date'])
Parse the Date column while loading the CSV, then make it the index so date-aware selection and aggregation are immediately available. section 10.10
Querying historical oil prices
With a DateTimeIndex, df.loc['1992-06-15'] selects one date, df.loc['1992-06'] selects every row in June, and df.loc['1987'] selects the entire year. Applying mean to the selected Price values produces period-specific averages. A date slice such as df.loc['2003-09':'2014-07'] includes both endpoints. section 10.10
Useful time-series operations include:
- Select rows by complete or partial dates with loc. section 10.8
- Slice an interval by specifying starting and ending dates. section 10.8
- Resample observations into periods such as days, months, years, or six-month intervals, then apply aggregations. section 10.8
- Combine resampling with sorting and dropna to find unusually high daily or monthly averages. section 10.14
Comparing tipping rates
After setting pickup time as the index, resample the tip_percentage series by day, sort the resulting means, and inspect the highest-tipping dates. Restricting the data to January and July before resampling avoids unrelated months and supports a direct seasonal comparison. section 10.14
The transferable pattern is simple: convert timestamps, place them in the index, select the relevant period, resample when needed, and aggregate or inspect the result. section 10.17








