Suppose I have a Pandas df
col_name
1 [16, 4, 30]
2 [5, 1, 2]
3 [4, 5, 52, 888]
4 [1, 2, 4]
5 [5, 99, 4, 75, 1, 2]
I would like to remove all the elements in the whole column that appears less than x
times, for example let's take x = 3
It means that I would like to have the result looks like:
col_name
1 [4]
2 [5, 1, 2]
3 [4, 5]
4 [1, 2, 4]
5 [5, 4, 1, 2]
The result df basically removes the number 16, 30, 52, 888, 99 and 75 because it appears less than 3 times in the column.
I tried using Counter
from collections
but it didn't work.
Really appreciate if you could give me any hints. Thanks in advance.