当我试图创建一个使用索引作为x值,价格作为y值的图时,我总是得到"TypeError: len() of unsized object“。
def tsplot2(y, title, lags=None, figsize=(12,8)):
if not isinstance(y, pd.Series):
y = pd.Series(y)
fig= plt.figure(figsize=figsize)
layout=(2,2)
ts_ax=plt.subplot2grid(layout, (0,0))
hist_ax=plt.subplot2grid(layout, (0,1))
acf_ax=plt.subplot2grid(layout, (1,0))
pacf_ax=plt.subplot2grid(layout, (1,1))
y.plot(ax=ts_ax)
ts_ax.set_title(title, fontsize=14, fontweight='bold')
y.plot(ax=hist_ax, kind='hist', bins=25)
hist_ax.set_title('Histogram')
smt.graphics.plot_acf(y, lags=lags, ax=acf_ax)
smt.graphics.plot_pacf(y, lags=lags, ax=pacf_ax)
sns.despine()
plt.tight_layout()
return ts_ax, acf_ax, pacf_ax
num_var= len(series.iloc[1,:])
for i in range(0, num_var):
tsplot2(series.iloc[:,i].dropna() , title=series.columns[i], lags=48)发布于 2018-12-24 02:12:48
我修复了代码。我删除了"if not isinstance(y,pd.Series):y= pd.Series(y)“,当我只需将序列插入到函数中时,也不需要使用for循环。
https://stackoverflow.com/questions/53900416
复制相似问题