In [ ]:
from datascience import *
import numpy as np

%matplotlib inline
import matplotlib.pyplot as plots
plots.style.use('fivethirtyeight')

Ranges

In [ ]:
np.arange(5)
In [ ]:
np.arange(7, 25)
In [ ]:
np.arange(5, 25, 10)
In [ ]:
np.arange(5, 26, 10)
In [ ]:
np.arange(5, 25.01, 10)
In [ ]:
 

Creating a Table from Scratch

In [ ]:
Table()
In [ ]:
streets = make_array('Bancroft', 'Durant', 'Channing', 'Haste')
In [ ]:
streets
In [ ]:
Table().with_column('Street name', streets)
In [ ]:
southside = Table().with_column('Street name', streets)
In [ ]:
# creates a new table with the specified column
southside.with_column('Blocks away from campus', np.arange(4))
In [ ]:
southside
In [ ]:
southside = southside.with_column('Blocks away from campus', np.arange(4))
In [ ]:
southside

Reading a Table from a File

In [ ]:
minard = Table.read_table('minard.csv')
In [ ]:
minard

Selecting data in a column

In [ ]:
minard.select('Survivors')
In [ ]:
minard.column('Survivors')
In [ ]:
minard.column('Survivors').item(0)

Extending a table with a new column

In [ ]:
initial_count = minard.column('Survivors').item(0)
initial_count
In [ ]:
proportion_surviving = minard.column('Survivors')/initial_count
proportion_surviving
In [ ]:
minard = minard.with_column('Percent surviving', proportion_surviving)
In [ ]:
minard
In [ ]:
minard.set_format('Percent surviving', PercentFormatter)

Working with Columns

In [ ]:
movies = Table.read_table('movies_by_year_with_ticket_price.csv')
In [ ]:
movies.show()
In [ ]:
movies.labels
In [ ]:
movies.num_rows
In [ ]:
number_of_tix = movies.column('Total Gross') * (10 ** 6) / movies.column('Average Ticket Price')
In [ ]:
movies = movies.with_column('Number of tickets', number_of_tix)
In [ ]:
movies
In [ ]:
movies.set_format(5, NumberFormatter)
In [ ]:
movies.plot('Year', 'Number of tickets')

Rows

In [ ]:
movies.where('Year', are.between(2000, 2005))
In [ ]:
movies.where('#1 Movie', are.equal_to('Avatar'))
In [ ]:
movies.where('#1 Movie', 'Avatar')
In [ ]:
movies.where('#1 Movie', are.containing('Harry Potter'))
In [ ]:
movies.where('Number of Movies', are.below(450))
In [ ]:
movies.where('Year', are.above(2010))
In [ ]:
movies.take(3)
In [ ]:
movies.take(np.arange(4))
In [ ]:
 
In [ ]:
 
In [ ]: