Issue
I have a dataframe
country | values |
---|---|
BG | 20 |
BG | 4 |
BG | 3 |
BG | -3 |
BG | -20 |
DE | 20 |
DE | 3 |
DE | -20 |
IND | 20 |
IND | -2 |
I want to filter the dataframe in such a way that values from BG should be < absolute (5) and all other countries should be < 5 such that the dataframe becomes
country | values |
---|---|
BG | 4 |
BG | 3 |
BG | -3 |
DE | 3 |
DE | -20 |
IND | -2 |
Solution
Use:
>>> df[(df["country"].eq("BG")&df["values"].abs().lt(5))|(df["country"].ne("BG")&df["values"].lt(5))]
country values
1 BG 4
2 BG 3
3 BG -3
6 DE 3
7 DE -20
9 IND -2
Answered By - not_speshal
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.