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
To verify that it's not just a problem setting any columns as categorical, I tried setting all columns to categorical, which works just fine:
set_cat=lambdax: x.astype('category')
dfb=pdf.apply(set_cat)
>>>print('Applied to whole frame: dtype={}'.format(dfb['gender'].dtype))
Appliedtowholeframe: dtype=category
Finally, I tried just using a for loop to duplicate the final result, to make sure that mixed categorical / non-categorical columns can coexist like this:
Per this SO question, using
apply()
to convert multipleDataFrame
columns to categorical does not work unless all columns are categorical.An MWE demonstrating the issue can be found at this gist for easy copy-paste.
Using this for example data:
I tried to use
pdf.apply()
to convert'gender'
and'nationality'
to categorical columns:To make sure that the problem isn't just that I'm never reaching the
x.astype('category')
branch of thelambda
expression, I added in an alert:To verify that it's not just a problem setting any columns as categorical, I tried setting all columns to categorical, which works just fine:
Finally, I tried just using a for loop to duplicate the final result, to make sure that mixed categorical / non-categorical columns can coexist like this:
Is this the desired behavior?
The text was updated successfully, but these errors were encountered: