You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In [70]: cat=pd.Categorical(['a', 'b', 'c'])
In [71]: obj=pd.Series(['a', 'b', 'c'])
In [72]: num=pd.Series([1, 2, 3])
In [73]: df=pd.concat([pd.Series(cat), obj, num], axis=1, keys=['cat', 'obj', 'num'])
In [74]: dfOut[74]:
catobjnum0aa11bb22cc3In [75]: df.dtypesOut[75]:
catcategoryobjobjectnumint64dtype: objectIn [76]: df.dtypes=='category'---------------------------------------------------------------------------TypeErrorTraceback (mostrecentcalllast)
<ipython-input-76-48fb3d0c49cf>in<module>()
---->1df.dtypes=='category'/Users/tom/Envs/py3/lib/python3.4/site-packages/pandas-0.14.1_291_g7a8a030-py3.4-macosx-10.9-x86_64.egg/pandas/core/ops.pyinwrapper(self, other)
579580# scalars-->581res=na_op(values, other)
582ifnp.isscalar(res):
583raiseTypeError('Could not compare %s type with Series'/Users/tom/Envs/py3/lib/python3.4/site-packages/pandas-0.14.1_291_g7a8a030-py3.4-macosx-10.9-x86_64.egg/pandas/core/ops.pyinna_op(x, y)
526msg="Cannot compare a Categorical for op {op} with type {typ}. If you want to \n" \
527"compare values, use 'series <op> np.asarray(cat)'."-->528raiseTypeError(msg.format(op=op,typ=type(y)))
529ifx.dtype==np.object_:
530ifisinstance(y, list):
TypeError: CannotcompareaCategoricalforop<built-infunctioneq>withtype<class'str'>. Ifyouwanttocomparevalues, use'series <op> np.asarray(cat)'.
For comparison
In [77]: df.dtypes=='object'Out[77]:
catFalseobjTruenumFalsedtype: boolIn [78]: df.dtypes=='int64'Out[78]:
catFalseobjFalsenumTruedtype: bool
This doesn't work either: In [87]: df.dtypes == df.cat.dtype (raise the same TypeError)
The text was updated successfully, but these errors were encountered:
Should this work?
For comparison
This doesn't work either:
In [87]: df.dtypes == df.cat.dtype
(raise the same TypeError)The text was updated successfully, but these errors were encountered: