I have a list:
l = [4,1,6,7]
and a dataframe df
:
0 1 2 3
0 1 2 3 4
1 5 4 1 0
2 7 5 0 9
And I want, for each element in the list, get the amount of numbers that are smaller than him in the column of its location in the dataframe. So here, the output will be:
[1,0,3,2]
What is the best way to do it?
CodePudding user response:
You can simply do:
df.lt(l).sum().to_list()
output:
[1, 0, 3, 2]
input dataframe:
>>> df
0 1 2 3
0 1 2 3 4
1 5 4 1 0
2 7 5 0 9