Pandas cat.categories.isin list, is this a bug?

zljubisic at gmail.com zljubisic at gmail.com
Thu May 17 03:49:17 EDT 2018


Hi Matt,

> (Including python-list again, for lack of a reason not to. This
> conversation is still relevant and appropriate for the general Python
> mailing list -- I just meant that the pydata list likely has many more
> Pandas users/experts, so you're more likely to get a better answer,
> faster, from a more specialized group.)

OK, for now we will stay here, but in the future I will use pydata as you have suggested.

> Selecting all rows that have categories is a bit simpler than what you
> are doing -- your issue is that you are working with the *set of
> distinct categories*, and not the actual vector of categories
> corresponding to your data.

Yes, now I got it thanks to your explanation. 
df.CRM_assetID.cat.categories means unique categories of the CRM_assetID field.
Now I am using df_cat[df_cat.CRM_assetID.isin({'V1254748', 'V805722', 'V1105400'})].shape to select all rows that have relevant categories.
Thanks for the set instead of list as well. Very good tip.
Everything works as it should now. 

Matt, you were more than helpful.
Thank you very very much.

Best regards.



More information about the Python-list mailing list