lab03.pdf - lab03(autosaved Logout Control Panel Python 3 Not Trusted Lab 3 Tables Welcome to lab 3 This week we will focus on manipulating tables

lab03.pdf - lab03(autosaved Logout Control Panel Python 3...

This preview shows page 1 - 3 out of 12 pages.

lab03 (autosaved) Logout Control Panel Python 3 Not Trusted Lab 3: Tables Welcome to lab 3! This week, we will focus on manipulating tables. Tables are described in Chapter 6 of the text. First, set up the tests and imports by running the cell below. In [ ]: import numpy as np from datascience import * # These lines load the tests. from client.api.notebook import Notebook ok = Notebook( 'lab03.ok' ) 1. Introduction For a collection of things in the world, an array is useful for describing a single attribute of each thing. For example, among the collection of US States, an array could describe the land area of each. Tables extend this idea by describing multiple attributes for each element of a collection. In most data science applications, we have data about many entities, but we also have several kinds of data about each entity. For example, in the cell below we have two arrays. The first one contains the world population in each year (as estimated by the US Census Bureau), and the second contains the years themselves (in order, so the first elements in the population and the years arrays correspond). In [ ]: population_amounts = Table.read_table( "world_population.csv" ).column( "Population" ) years = np.arange( 1950 , 2015 + 1 ) print ( "Population column:" , population_amounts) print ( "Years column:" , years) Suppose we want to answer this question: When did world population cross 6 billion? You could technically answer this question just from staring at the arrays, but it's a bit convoluted, since you would have to count the position where the population first crossed 6 billion, then find the
Image of page 1
corresponding element in the years array. In cases like these, it might be easier to put the data into a Table , a 2-dimensional type of dataset. The expression below: creates an empty table using the expression Table() , adds two columns by calling with_columns with four arguments, assignes the result to the name population , and finally evaluates population so that we can see the table. The strings "Year" and "Population" are column labels that we have chosen. Ther names population_amounts and years were assigned above to two arrays of the same length. The function with_columns (you can find the documentation here) takes in alternating strings (to represent column labels) and arrays (representing the data in those columns), which are all separated by commas. In [ ]: population = Table().with_columns( "Population" , population_amounts, "Year" , years ) population Now the data are all together in a single table! It's much easier to parse this data--if you need to know what the population was in 1959, for example, you can tell from a single glance. We'll revisit this table later. 2. Creating Tables Question 2.1. In the cell below, we've created 2 arrays. Using the steps above, assign top_10_movies to a table that has two columns called "Rating" and "Name", which hold top_10_movie_ratings and top_10_movie_names respectively.
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 12 pages?

  • Fall '17
  • Column, Equals sign, Row, IMDB, Qs For Lab 3 Updated

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors