Slicing time-series data

Now that we know how to handle 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 very useful when you are working with time-series datasets. Instead of using indices, we will use timestamp 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 ...

Get Artificial Intelligence with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.