Slicing time series data
Now that we loaded the time series data, let's see how we can slice it. The process of slicing refers to dividing the data into various sub-intervals and extracting relevant information. This is useful when we are working with time series datasets. Instead of using indices, we will use timestamps to slice our data.
Create a new Python file and import the following packages:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from timeseries import read_data
Load the third column (zero-indexed) from the input data file:
# Load input data
index = 2
data = read_data('data_2D.txt', index)
Define the start and end years, and then plot the data with year-level granularity:
# Plot data with year-level granularity
start = '2003'
end = '2011'
plt.figure()
data[start:end].plot()
plt.title('Input data from ' + start + ' to ' + end)
...