from datascience import *
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plots
plots.style.use('fivethirtyeight')
streets = make_array('Bancroft', 'Durant', 'Channing', 'Haste')
streets
southside = Table().with_columns(
'Street', streets,
'Blocks from Campus', np.arange(4)
)
southside
type(southside.row(0))
southside = southside.with_row(['Dwight', 4])
southside
southside = southside.with_column('One-Way', ['Yes', 'Yes', 'No', 'Yes', 'Yes'])
southside
southside.column('One-Way')
nba = Table.read_table('nba_salaries.csv')
nba
nba = nba.relabeled(3, 'SALARY').drop('TEAM')
nba
#Create an array containing the names of all point guards (PG) who make more than $15M/year
nba.where(1, 'PG').where(2, are.above(15)).column(0)
nba.where('POSITION', 'PG').where('SALARY', are.above(15)).column('PLAYER')
nba.with_row(['Bernie', 'Mascot', 100])
nba.where('PLAYER', are.containing('Bern'))
nba2 = nba.with_row(['Bernie', 'Mascot', 100])
nba2.where('PLAYER', are.containing('Bern'))
full = Table.read_table('nc-est2014-agesex-res.csv')
full
partial = full.select('SEX', 'AGE', 'POPESTIMATE2010', 'POPESTIMATE2014')
partial
simple = partial.relabeled('POPESTIMATE2010', '2010').relabeled('POPESTIMATE2014', '2014')
simple
simple.sort('AGE', descending=True)
no_999 = simple.where('AGE', are.below(999))
no_999.sort("AGE", descending=True)
everyone = no_999.where('SEX', 0).drop('SEX')
males = no_999.where('SEX', 1).drop('SEX')
females = no_999.where('SEX', 2).drop('SEX')
females
females.sort('2014', descending=True)
males.sort('2014', descending=True)
pop_2014 = Table().with_column(
'Age', males.column('AGE'),
'Males', males.column('2014'),
'Females', females.column('2014')
)
pop_2014
percent_females = 100 *pop_2014.column('Females')/(pop_2014.column('Males') + pop_2014.column('Females'))
counts_and_percents = pop_2014.with_column('Percent Female', percent_females)
counts_and_percents
counts_and_percents.plot('Age', 'Percent Female')
pop_2014
pop_2014.plot('Age')
pop_2014.where('Age', are.between(65, 75))
2014 - np.arange(67, 73)
everyone
everyone = everyone.with_column(
'Change', everyone.column('2014') - everyone.column('2010')
)
everyone.sort('Change', descending=True)
everyone.with_column(
'Growth Rate', (everyone.column('2014')/everyone.column('2010')) ** (1/4) - 1
).sort('Growth Rate', descending=True)