Computing Standard Deviation without packages in Python?

opencsv, python-3.x, standard-deviation, statistics

Solution

If you allow the use of the standard library,

import math

xs = [0.5,0.7,0.3,0.2]     # values (must be floats!)
mean = sum(xs) / len(xs)   # mean
var  = sum(pow(x-mean,2) for x in xs) / len(xs)  # variance
std  = math.sqrt(var)  # standard deviation

If not, you need to approximate `sqrt` by hand. For example, you can use binary search or Newton's Method. Here's a wikipedia page for methods of doing so

Problem

I'm trying to figure out how to create a script which calculates a standard deviation for a file. As an example, say I DLed a csv with a list of values on it. I want to find the SD of these values by running a python program. We are not using numpy here!

Original source