A datetime index gives a pandas DataFrame date labels that support natural time-based selection. Selecting a year, month, or date range returns the matching rows, including the ending date of a slice. section 10.10
Useful operations include:
- Select one date, month, year, or inclusive date range with .loc. section 10.10
- Use index.is_quarter_end to mask rows occurring on the final day of each quarter. section 10.10
- Use resample to aggregate values by periods such as weeks, months, or years; incomplete periods still appear. section 10.10
filename = '../data/wti-daily.csv'
df = pd.read_csv(filename,
parse_dates=['Date'],
index_col=['Date'])
Create the index while loading daily oil prices by parsing Date values and assigning them as the DataFrame index. section 10.10
