Book Image

Time Series Analysis with Python Cookbook

By : Tarek A. Atwan
Book Image

Time Series Analysis with Python Cookbook

By: Tarek A. Atwan

Overview of this book

Time series data is everywhere, available at a high frequency and volume. It is complex and can contain noise, irregularities, and multiple patterns, making it crucial to be well-versed with the techniques covered in this book for data preparation, analysis, and forecasting. This book covers practical techniques for working with time series data, starting with ingesting time series data from various sources and formats, whether in private cloud storage, relational databases, non-relational databases, or specialized time series databases such as InfluxDB. Next, you’ll learn strategies for handling missing data, dealing with time zones and custom business days, and detecting anomalies using intuitive statistical methods, followed by more advanced unsupervised ML models. The book will also explore forecasting using classical statistical models such as Holt-Winters, SARIMA, and VAR. The recipes will present practical techniques for handling non-stationary data, using power transforms, ACF and PACF plots, and decomposing time series data with multiple seasonal patterns. Later, you’ll work with ML and DL models using TensorFlow and PyTorch. Finally, you’ll learn how to evaluate, compare, optimize models, and more using the recipes covered in the book.
Table of Contents (18 chapters)

Plotting time series data using pandas

The pandas library offers built-in plotting capabilities for visualizing data stored in a DataFrame or Series data structure. In the backend, these visualizations are powered by the Matplotlib library, which is also the default option.

The pandas library offers many convenient methods to plot data. Simply calling DataFrame.plot() or Series.plot() will generate a line plot by default. You can change the type of the plot in two ways:

  • Using the .plot(kind="<sometype>") parameter to specify the type of plot by replacing <sometype> with a chart type. For example, .plot(kind="hist") will plot a histogram while .plot(kind="bar") will produce a bar plot.
  • Alternatively, you can extend .plot(). This can be achieved by chaining a specific plot function, such as .hist() or .scatter(), for example, using .plot.hist() or .plot.line().

This recipe will use the standard pandas .plot() method with...