python pandas- AttributeError: 'Series' object has no attribute 'columns'?

python pandas- AttributeError: 'Series' object has no attribute 'columns'?

我正在尝试计算特定列的当前行值 'df1' 落在前 5 行(在 2 个并排列中)的低-高范围值之间的次数。这是一个后续问题 - Dickster 已经完成了繁重的工作

Series().between()方法不配合,抱怨AttributeError: 'Series' object has no attribute 'columns'。我不明白我是如何涉及 columns 属性的。

list1 = [[21,101],[22,110],[25,113],[24,112],[21,109],[28,108],[30,102],[26,106],[25,111],[24,110]]
dict1 = {}
dict1['df1'] = pd.DataFrame(list1,index=pd.date_range('2000-1-1',periods=10, freq='D'), columns=list('AB'))
dict1['df2'] = pd.DataFrame(dict1['df1'] * (1-.05))
pan_so = pd.Panel(dict1)
pan_so = pan_so.transpose(2,1,0)

x = pan_so.ix[0,:,:]
def btwn(x):  # x is a dataframe
    y = x['df1'].rolling(center=False,window=6)
    z = x['df2'].rolling(center=False,window=6)
    x['cnt_btwn'] = pd.Series(pd.Series(y[:-1]).between(z[-1], y[-1], inclusive=True).sum())
    return x
btwn(x) 

我做错了什么?谢谢!

y[:-1] 访问不支持列索引的 Rolling 对象,这就是代码中 [:-1] 的含义。您应该在过滤之前应用转换函数并获得实际系列。