I have what I believe is a simple question but I can't find what I'm looking for in the docs.
I have a dataframe with a Categorical
column called mycol
with categories a
and b
and would like to be mask a subset of the dataframe as follows:
df_a = df[df.mycol.equal('a')]
Currently I am doing:
df_a = df[df.mycol.cat.codes.values==df.mycol.cat.categories.to_list().index('a')]
which is obviously extremely verbose and inelegant. Since df.mycol
has both the codes and the coded labels, it has all the information to perform this operation, so I'm wondering the best way to go about this...