Let's say I have a boolean column stored as a category in a pandas.DataFrame. But there's a twist - the underlying values are str, not bool. I.e., the values are "True"/"False", not True/False.
How do I:
- change the dtype of the underlying category values (e.g. from
"True"toTrue) and - continue storing the field as a
category?
Having the boolean values as strings is an issue with DataFrame.query, for example. I have to specify DataFrame.query("field == 'True'"), which is pretty horrendous lol.
FYI - I don't want to do DataFrame.astype(dict(field=bool)), because then i lose the memory efficiency from category. i want to keep the category dtype.