无大小对象的len(),例如num\u var=len(能源.iloc[1, :])

2024-04-26 08:07:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我不断得到“TypeError:len()of unsized object” 当试图创建一个使用索引作为x值和价格作为y值的绘图时。你知道吗

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)

Tags: lenplottitlepltaxhistserieslayout