Issue
I have this graph with a line that follows y = x
function and shows points in there. Like in the following image:
My question is: Given n points in the graph (columns x and y), how can I get the percent of points below and above the line?
What I tried is this:
def function(df, y):
total = len(df)
count = (df[y] > df.index).sum()
percent = (count*100)/total
return percent
Where total
is the total of points of a dataframe and count
is the sum of all values of the column y greater than the index. That point of view is wrong.
What I want is, for example, given 10 points, says 70% of the points are below of the line and can count 7 points below the line.
Solution
Points below the line satisfy the equation x > y
. So, the percentage is:
df[df.x > df.y].size / df[[x, y]].size * 100
Answered By - Nuri Taş
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.