I\'m running some models in Python, with data subset on categories.
For memory usage, and preprocessing, all the categorical variables are stored as category data t
Your problem is in that you are assigning z.get_group(i) to x. x is now a copy of a portion of z. Your code will work fine with this change
z.get_group(i)
x
z
for i in z.groups: x = z.get_group(i).copy() # will no longer be tied to z x.x = x.x.cat.remove_unused_categories()