Operations On Column Length
Firstly, sorry if I have used the wrong language to explain what I'm operating on, I'm pretty new to python and still far from being knowledgeable about it. I'm currently trying to
Solution 1:
You are probably making an error with integer math, but your statement
x1percentage = (xtotal/x1)*100
doesn't really make sense. xtotal
is an integer and x1
is an array of values, len(x1)
is an integer equal to the size of x1
, and regardless to get a percentage you would want x1/xtotal
.
If you tried len(x1)/xtotal
, you would get zero as you mentioned, because python would cast both variables as integers and use integer math, which the result is zero.
The solution cast one or both values as floats to force floating point division by
x1percentage = (xtotal / float(x1)) * 100
Post a Comment for "Operations On Column Length"