I have written the following function:
def drop_low_counts(df, column):
for value in df[column]:
if df[column].value_counts()[str(value)] < 5 == True:
df.drop(df[df[column] == str(value)].index, axis=0)
return df
It is supposed to drop the rows of a df where the value in a certain column is repeated less than 5 times in the column. I am not sure where I have gone wrong, but when I run the function the df does not change at all. I have been running it as a regular function, but maybe I need to use df.apply()
? Thank you for the help!