sns.histplot(data=DS1[(DS1.TuWgt<30000) & (DS1.TuType!=1001)], x="TuWgt",hue="TuType",multiple="stack")
So this is the line I'm trying to run. TuType is a category.
TypeError: unsupported operand type(s) for &: 'int' and 'Categorical'
CodePudding user response:
The & operator has a higher priority than the < and != operators, so your code is being executed like this:
sns.histplot(data=DS1[DS1.TuWgt < (30000 & DS1.TuType) != 1001], x="TuWgt",hue="TuType",multiple="stack")
...which is wrong (and confusing).
Instead, add parentheses around the conditions joined by &, like this:
sns.histplot(data=DS1[(DS1.TuWgt<30000) & (DS1.TuType!=1001)], x="TuWgt",hue="TuType",multiple="stack")
CodePudding user response:
I'm not sure what are your dtypes are, but if you are sure TuWgt and TuType are numeric only, try to wrap the conditions into parentheses:
sns.histplot(data=DS1[(DS1.TuWgt<30000) & (DS1.TuType!=1001)], x="TuWgt",hue="TuType",multiple="stack")
Otherwise & operation has higher priority, so you try to apply & to 30000 and DS1.TuType
