NameGenderClassification icon indicating copy to clipboard operation
NameGenderClassification copied to clipboard

Missing data downloading

Open brianspiering opened this issue 9 years ago • 0 comments

The code assumes you have downloaded and unzipped the files. Here a way to handle it

def load_data():
    my_data = np.genfromtxt('yob2014.txt', 
                        delimiter=',', 
                        dtype=[('name','S50'), ('gender','S1'),('count','i4')],
                        converters={0: lambda s:s.lower()})

try:
    load_data()
except IOError:
    from urllib.request import urlretrieve
    urlretrieve('https://www.ssa.gov/oact/babynames/names.zip', 'yob2014.zip')

    from zipfile import ZipFile
    with ZipFile("yob2014.zip","r") as zip_ref:
        zip_ref.extractall()

    load_data()

brianspiering avatar Apr 21 '16 16:04 brianspiering