def acf(series):
    n = len(series)
data = numpy.asarray(series)
mean = numpy.mean(data)
c0 = numpy.sum((data - mean) ** 2) / float(n)

def r(h):
    acf_lag = ((data[:n - h] - mean) * (data[h:] - mean)).sum() / float(n) / c0
return round(acf_lag, 3)
x = numpy.arange(n)
acf_coeffs = map(r, x)
return acf_coeffs
Estimate Autocorrelation using Python