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