Reputation: 1998
Had a simple question, I am trying to get a rate or % by dividing the sum of one column ( Values ) by all the rows in that df.
DF:
ID | Values
D 1
B 0
R 1
etc...
I want to take the sum of Values column an divide by count or number of rows inn the df.
Tryin something like
df[(df.Values.sum()] / len(df.ID)
Not sure if I am on right track
thanks!
Upvotes: 1
Views: 933
Reputation: 6639
Scott's method is stellar and I would do the same as him. However, correcting your code would be:
df['values'].sum() / len(df)
Upvotes: 2