Book Image

Python for Finance

By : Yuxing Yan
Book Image

Python for Finance

By: Yuxing Yan

Overview of this book

Table of Contents (20 chapters)
Python for Finance
About the Author
About the Reviewers

Using Pandas and statsmodels

We give a few examples in the following section for the two modules we are going to use intensively in the rest of the book. Again, the Pandas module is for data manipulation and the statsmodels module is for the statistical analysis.

Using Pandas

In the following example, we generate two time series starting from January 1, 2013. The names of those two time series (columns) are A and B:

>>>import numpy as np
>>>import pandas as pd

First, we import both NumPy and Pandas modules. The pd.date_range() function is used to generate an index array. The x variable is a Pandas' data frame with dates as its index. Later in this chapter, we will discuss pd.DataFrame(). The columns() function defines the names of those columns. Because the seed() function is used in the program, anyone can generate...