Basically, I am trying to find out the categorical columns which has less than 3 duplications of every class. For eg, In the attached screenshot, I have a column called Name, 'Type 1' and I want these column names to be returned in my output if each category in these columns (Say Bulbasaur, Nidoino) are present < 3 times and the reason why I want to perform this is in such cases where a column mostly has unique values, I can label encode them.
Below is the code I tried out, but I am not finding the solution.
Could someone please help?
labels = [str(Training_data[object_cols].unique()[i]) for i in range(Training_data[object_cols].nunique())]
values = [Training_data[object_cols].value_counts()[i] for i in range(Training_data[object_cols].nunique())]
labels
values
Target_dis = pd.DataFrame((labels, values))
Target_dis = Target_dis.T
Target_dis.columns = ['Labels', 'Counts']
Target_dis = Target_dis.sort_values('Counts', ascending=False)
Target_dis
