I want to create a function that filter on a specific value in a column of an dataframe(
My dataframe has the follow columns and value:
| Zoekterm | High_bias |
|---|---|
| Man | 1 |
| Man | 1 |
| Vrouw | 1 |
| kind | 0 |
I wrote a function that filter on a specific value see below
Def most_likey_bias():
bias = data['high_bias'] == 1
if bias.any():
print(data.loc[bias,['High_bias','Zoekterm']
print(most_likey_bias())
The outcome of the table is:
| Zoekterm | High_bias |
|---|---|
| vrouw | 1 |
| kind | 1 |
This table gives back which "Zoekterm" has a value of 1
But because the " Zoekterm" has duplicates of the same name i want a table that gives me a count of each zoekterm
So the table that i want is:
This means a table where it counts for each "Zoekterm" how much "High bias" it has based on an specific value (1)
| Zoekterm | High_bias |
|---|---|
| Man | 4 |
| Vrouw | 2 |
| kind | 5 |
I tried with groupby or with count, but i don't get it. Could someone give me some tips.