""" This exercise allows you to take a brief look at DB capabilities of python and the SQL Alchemy library
this directory contains the names.zip file, which contains lists of baby names given in the US, one list per year. Each list is a csv file of the following format:
name, sex, number of names
List available at: http://www.ssa.gov/oact/babynames/limits.html
After unzipping the file, write a function that can parse the file and return a list of (name, sex, number). Use namedtuples for each row.
Using the DB API from python, create a table that will contain contain all the information of one csv file. You may use the following SQL statement to create a table:
CREATE TABLE babies (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(100), sex VARCHAR(10), age INTEGER)
Once the table is created, insert the data obtained from the call to the function written in question 1.
Use the database to answer the following questions:
- how many names have more than 5000 occurences in 2005 ?
- how many babies were born in the US in 2005 (assuming every born baby is included in the csv file) ?
Using SQL Alchemy, create a table object that represents the previous babies table. Use this table to answer the same questions as in question 2
Use the ORM capabilities of SQLAlchemy to build a Baby object that contains a name, an age and a sex. Use the ORM to answer the same questions as in question 2
Try to do the same exercises, but including every year (you need to add a column to include the year in your SQL table). """