There is a great solution in R.
My df.column looks like:
Windows
Windows
Mac
Mac
Mac
Linux
Windows
...
I want to replace low frequency categories with 'Other' in this df.column vector. For example, I need my df.column to look like
Windows
Windows
Mac
Mac
Mac
Linux -> Other
Windows
...
I would like to rename these rare categories, to reduce the number of factors in my regression. This is why I need the original vector. In python, after running the command to get the frequency table I get:
pd.value_counts(df.column)
Windows 26083
iOS 19711
Android 13077
Macintosh 5799
Chrome OS 347
Linux 285
Windows Phone 167
(not set) 22
BlackBerry 11
I wonder if there is a method to rename 'Chrome OS', 'Linux' (low frequency data) into another category (for example category 'Other', and do so in an efficient way.