df.dtypes
Close float64
eqId int64
date object
IntDate int64
expiry int64
delta int64
ivMid float64
conf float64
Skew float64
psc float64
vol_B category
dtype: object
gb = df.groupby([df['vol_B'],df['expiry']])
gb.describe()
我收到一条很长的错误消息,最后一行是
AttributeError: 'Categorical' object has no attribute 'flags'
当我分别对每个groupby
执行groupby
时,它们(独立地)工作得很好,我只能执行多个groupby
,其中一个变量是“bin”。
此外,当我使用其他2个变量时,我能够执行多个gb = df.groupby([df['delta'],df['expiry']])
& ndash,我成功执行了此操作:
replace
答案 0 :(得分:7)
我遇到了与OP类似的问题,并在寻找解决方案时发现了这个问题。经过大熊猫documentation for categorical variables后,对我有用的简单黑客是在分组之前改变分类变量的类型。
由于vol_B是您的分类变量,因此您应该尝试以下
#Depending on the content of vol_B you can do astype(int) or astype(float) as well.
gb = df.groupby([df['vol_B'].astype(str), df['expiry']])
我没有详细说明为什么会有效,但事实并非如此,但如果我进入它,我会更新答案。