python 时间序列分解 stl_jupyter notebook运行时间序列分解STL趋势和季节
1.?"ImportError: No module named" when trying to run Python script
notebook不知道module的路徑在哪,默認只知道current path
先找到包所在位置
pip show --verbose pandas
再告訴notebook
import sys
sys.path.append('/usr/local/lib/python2.7/dist-packages')
2. ?安裝分解時間序列用到的包
pip install statsmodels
3.?AttributeError: 'Index' object has no attribute 'inferred_freq'
seasonal_decompose()對pandas Series需要是datetime
import pandas as pd
from pandas import Series
from matplotlib import pyplot
from statsmodels.tsa.seasonal import seasonal_decompose
df = pd.read_csv('data.csv', header=0)
df.Date = pd.to_datetime(df.Date,errors='coerce')
df = df.set_index('Date')
result = seasonal_decompose(df, model='mutiplicative',freq=7)
result.plot()
pyplot.show()
4. notebook顯示圖片太小,變大
import matplotlib.pyplot as plt
fig_size = [20, 9]
plt.rcParams["figure.figsize"] = fig_size
總結
以上是生活随笔為你收集整理的python 时间序列分解 stl_jupyter notebook运行时间序列分解STL趋势和季节的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python中all是什么意思_Pyth
- 下一篇: python standard lib_