I have a dataframe like below:
| Feature | value | frequency | label |
|---|---|---|---|
| age_45_and_above | No | 2700 | negative |
| age_45_and_above | No | 1707 | positive |
| age_45_and_above | No | 83 | other |
| age_45_and_above | Yes | 222 | negative |
| age_45_and_above | Yes | 15 | positive |
| age_45_and_above | Yes | 8 | other |
| age_45_and_above | [Null] | 323 | negative |
| age_45_and_above | [Null] | 8 | other |
| age_45_and_above | [Null] | 5 | positive |
| talk | No | 20 | negative |
| talk | No | 170 | positive |
| talk | No | 500 | other |
| talk | Yes | 210 | negative |
| talk | Yes | 1500 | positive |
| talk | Yes | 809 | other |
| talk | [Null] | 234 | negative |
| talk | [Null] | 43 | other |
| talk | [Null] | 85 | positive |
and so on.
for each feature group, I want to find the maximum frequency with all its related row data, like if the feature is age_45_and_above then by looking for NO group we have 3 rows with different frequency and label, I want to report the maximum one with it's related data.
I've tried groupby in different ways:
result.groupby(['Feature', 'Value'])['Frequency', 'Predict'].max()
or this one, with this one, I'm getting multi-Index dataframe which is not the desired results:
result.groupby(['Feature', 'Value', 'Predict'])['Frequency'].max()
and so many failed attempts with idxmax, transfrom and ... .
the intended output I'm looking for looks like this:
| Feature | value | frequency | label |
|---|---|---|---|
| age_45_and_above | No | 2700 | negative |
| age_45_and_above | Yes | 222 | negative |
| age_45_and_above | [Null] | 323 | negative |
| talk | No | 500 | other |
| talk | Yes | 1500 | positive |
| talk | [Null] | 234 | negative |
Also, I wonder how to sum the frequencies for each <<Feature-value>> group except the max row as I don't know how to locate the max row, like in here for the first feature and value, <<age_45_and_above-No>> max is 2700, so the sum would be 1707+83.
Thanks for your time.