Saturday, June 22, 2013

python. plotting the normal distribution in 3,2,1, ... go!

Just for reference in case I needed later or should someone find it useful, this is the shortest path I've found to graphing the normal distribution using python

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
items = []
with open('data','r') as f:
    for line in f:
plt.plot(items, norm.pdf(items,np.mean(items),np.std(items)))

Tuesday, June 18, 2013

python. geocoding whith geopy

What if you have a bunch of mail addresses and need to get approximate coordinate positions? That's what geocoding is all about, and with geopy is as easy as it gets.

from geopy import geocoders
g = geocoders.GoogleV3()
place, (lat,lng) = g.geocode("AV. DIVISION DEL NORTE NO. 911-A COLONIA DEL VALLE BENITO JUAREZ")
print "%s: %.5f, %.5f" % (place, lat, lng)

And then, as if it were some sort of magic:

Avenida DivisiĆ³n del Norte 911, General Anaya, Benito Juarez, Mexico City, Federal District, Mexico: 19.35731, -99.15289


geopy includes geocoder classes for MediaWiki (with the GIS extension), Semantic MediaWiki, the Google v2 geocoder, the Yahoo! geocoder,geocoder.usBing Maps API, and GeoNames. The geocoder classes are located in geopy.geocoders.