- Practical Time Series Analysis
- Dr. Avishek Pal Dr. PKS Prakash
- 470字
- 2021-07-08 10:18:25
Time series data
The example of cross-sectional data discussed earlier is from the year 2010 only. However, instead if we consider only one country, for example United States, and take a look at its military expenses and central government debt for a span of 10 years from 2001 to 2010, that would get two time series - one about the US federal military expenditure and the other about debt of US federal government. Therefore, in essence, a time series is made up of quantitative observations on one or more measurable characteristics of an individual entity and taken at multiple points in time. In this case, the data represents yearly military expenditure and government debt for the United States. Time series data is typically characterized by several interesting internal structures such as trend, seasonality, stationarity, autocorrelation, and so on. These will be conceptually discussed in the coming sections in this chapter.
The internal structures of time series data require special formulation and techniques for its analysis. These techniques will be covered in the following chapters with case studies and implementation of working code in Python.
The following figure plots the couple of time series we have been talking about:

In order to generate the preceding plots we will extend the code that was developed to get the graphs for the cross-sectional data. We will start by creating two new Series to represent the time series of military expenses and central government debt of the United States from 1960 to 2010:
central_govt_debt_us = central_govt_debt.ix[central_govt_debt['Country Code']=='USA', :].T military_exp_us = military_exp.ix[military_exp['Country Code']=='USA', :].T
The two Series objects created in the preceding code are merged to form a single DataFrame and sliced to hold data for the years 2001 through 2010:
data_us = pd.concat((military_exp_us, central_govt_debt_us), axis=1) index0 = np.where(data_us.index=='1960')[0][0] index1 = np.where(data_us.index=='2010')[0][0] data_us = data_us.iloc[index0:index1+1,:] data_us.columns = ['Federal Military Expenditure', 'Debt of Federal Government'] data_us.head(10)
The data prepared by the preceding code returns the following table:

The preceding table shows that data on federal military expenses and federal debt is not available from several years starting from 1960. Hence, we drop the rows with missing values from the Dataframe data_us before plotting the time series:
data_us.dropna(inplace=True)
print('Shape of data_us:', data_us.shape)
As seen in the output of the print function, the DataFrame has twenty three rows after dropping the missing values:
Shape of data_us: (23, 2)
After dropping rows with missing values, we display the first ten rows of data_us are displayed as follows:

Finally, the time series are generated by executing the following code:
# Two subplots, the axes array is 1-d
f, axarr = plt.subplots(2, sharex=True)
f.set_size_inches(5.5, 5.5)
axarr[0].set_title('Federal Military Expenditure during 1988-2010 (% of GDP)')
data_us['Federal Military Expenditure'].plot(linestyle='-', marker='*', color='b', ax=axarr[0])
axarr[1].set_title('Debt of Federal Government during 1988-2010 (% of GDP)')
data_us['Debt of Federal Government'].plot(linestyle='-', marker='*', color='r', ax=axarr[1])
- ASP.NET Core:Cloud-ready,Enterprise Web Application Development
- ExtGWT Rich Internet Application Cookbook
- 解構產品經理:互聯網產品策劃入門寶典
- Python機器學習:數據分析與評分卡建模(微課版)
- 軟件測試項目實戰之性能測試篇
- 人臉識別原理及算法:動態人臉識別系統研究
- Linux環境編程:從應用到內核
- Bootstrap 4:Responsive Web Design
- CRYENGINE Game Development Blueprints
- Visual Basic語言程序設計基礎(第3版)
- Yii2 By Example
- Ubuntu Server Cookbook
- 小學生C++趣味編程從入門到精通
- Java核心技術速學版(第3版)
- 分布式系統架構與開發:技術原理與面試題解析