How do I create a pandas framework to match the top 20% value in a column?
There is a pandas dataframe:
df = pd.DataFrame({'c1':['a','b','c','d','e','f','g','h','i','j'],
'c2':[10,12,23,4,18,98,11,23,33,99]})
c1 c2
0 a 10
1 b 12
2 c 23
3 d 4
4 e 18
5 f 98
6 g 11
7 h 23
8 i 33
9 j 99
I want to create a new dataframe that only contains the top 20% of the rows according to the values in column c2, in this case:
output:
c1 c2
0 f 98
1 j 99
+3
source to share