from datascience import *
import numpy as np
Table.interactive_plots()
schools = Table.read_table('data/r1_with_students.csv')
schools
schools.group('Control')
schools.group('Control').barh('Control')
streams = Table.read_table('data/regional-global-daily-latest.csv', header = 1)
top_10 = streams.select('Track Name', 'Streams').take(np.arange(10))
top_10
top_10.barh('Track Name')
streams
streams.group('Artist') \
.sort('count', descending = True) \
.where('count', are.above(2))
streams.group('Artist') \
.sort('count', descending = True) \
.where('count', are.above(2)) \
.barh('Artist')
schools
schools.select('University', 'Number_students') \
.sort('Number_students', descending = True) \
.take(np.arange(15))
schools.select('University', 'Number_students') \
.sort('Number_students', descending = True) \
.take(np.arange(15)) \
.barh('University')
schools
schools.where('State', are.contained_in(['CA', 'TX', 'FL', 'NY', 'PA'])) \
.group('State', ...) \
.select(..., ...) \
.barh(...)
schools.take(np.arange(5)).barh('Control')
# Run this cell.
def remove_comma(s):
return int(s.replace(',', ''))
nominal = Table.read_table('data/gdp-nominal.csv')
ppp = Table.read_table('data/gdp-ppp.csv').drop(3)
gdp = nominal.join('Country/Territory', ppp) \
.drop(1, 3) \
.relabeled(['GDP(US$million)', 'GDP(millions of current Int$)'], ['GDP Nominal', 'GDP PPP'])
gdp = gdp.with_columns(
'GDP Nominal', gdp.apply(remove_comma, 'GDP Nominal'),
'GDP PPP', gdp.apply(remove_comma, 'GDP PPP')
)
gdp = gdp.sort('GDP Nominal', descending = True)
gdp
gdp.select('Country/Territory', 'GDP Nominal') \
.take(np.arange(15)) \
.barh('Country/Territory')
gdp.select('Country/Territory', 'GDP PPP') \
.take(np.arange(15)) \
.barh('Country/Territory')
gdp
gdp.take(np.arange(15)).barh('Country/Territory')
We can sort by GDP PPP, too:
gdp.sort('GDP PPP', descending = True).take(np.arange(15)).barh('Country/Territory')
Another example:
schools
schools.pivot('Control', 'State')
schools.pivot('Control', 'State') \
.where('Private (non-profit)', are.above(0)) \
.where('Public', are.above(0))
schools.pivot('Control', 'State') \
.where('Private (non-profit)', are.above(0)) \
.where('Public', are.above(0)) \
.barh('State')
schools.pivot('Control', 'State') \
.where('Private (non-profit)', are.above(0)) \
.where('Public', are.above(0)) \
.barh('State')
schools.pivot('Control', 'State') \
.where('Private (non-profit)', are.above(0)) \
.where('Public', are.above(0)) \
.barh('State', xaxis_title = 'Number of Universities',
title = 'Number of Private and Public R1 Universities in Each State',
width = 700,
height = 700)
top_gdp = gdp.take(np.arange(7))
top_gdp