I have a pandas dataframe say:
x | y | z |
---|---|---|
1 | a | x |
1 | b | y |
1 | c | z |
2 | a | x |
2 | b | x |
3 | a | y |
4 | a | z |
If i wanted top 2 values by x, I mean top 2 values by x column which gives:
x | y | z |
---|---|---|
1 | a | x |
1 | b | y |
1 | c | z |
2 | a | x |
2 | b | x |
If i wanted top 2 values by y, I mean top 2 values by y column which gives:
x | y | z |
---|---|---|
1 | a | x |
1 | b | y |
2 | a | x |
2 | b | x |
3 | a | y |
4 | a | z |
How can I achieve this?