Loading data as pandas objects from statsmodels
Statsmodels has quite a lot of sample datasets in its distributions. The complete list can be found at https://github.com/statsmodels/statsmodels/tree/master/statsmodels/datasets .
In this tutorial, we will concentrate on the copper dataset, which contains information about copper prices, world consumption, and other parameters.
Getting ready
Before we start, we might need to install patsy. It is easy enough to see if this is necessary just run the code. If you get errors related to patsy, you will need to execute any one of the following two commands:
sudo easy_install patsy pip install --upgrade patsy
How to do it...
In this section, we will see how we can load a dataset from statsmodels as a Pandas DataFrame
or Series
object.
Loading the data.
The function we need to call is
load_pandas
. Load the data as follows:data = statsmodels.api.datasets.copper.load_pandas()
This loads the data in a
DataSet
object, which containspandas
objects.Fitting...