lab04.pdf - lab04 October 8 2018 1 Lab 4 Functions and Visualizations Welcome to Lab 4 This week well learn about functions table methods such as apply

lab04.pdf - lab04 October 8 2018 1 Lab 4 Functions and...

This preview shows page 1 - 4 out of 17 pages.

lab04 October 8, 2018 1 Lab 4: Functions and Visualizations Welcome to Lab 4! This week, we’ll learn about functions, table methods such as apply , and how to generate visualizations! Recommended Reading: Applying a Function to a Column Visualizations First, set up the notebook by running the cell below. In [22]: import numpy as np from datascience import * # These lines set up graphing capabilities. import matplotlib % matplotlib inline import matplotlib.pyplot as plt plt . style . use( ' fivethirtyeight ' ) import warnings warnings . simplefilter( ' ignore ' , FutureWarning ) from ipywidgets import interact, interactive, fixed, interact_manual import ipywidgets as widgets from client.api.notebook import Notebook ok = Notebook( ' lab04.ok ' ) _ = ok . auth(inline = True ) ===================================================================== Assignment: Functions and Visualizations OK, version v1.12.5 ===================================================================== Successfully logged in as [email protected] 1
Image of page 1
1.1 1. Functions and CEO Incomes In this question, we’ll look at the 2015 compensation of CEOs at the 100 largest companies in California. The data was compiled from a Los Angeles Times analysis , and ultimately came from filings mandated by the SEC from all publicly-traded companies. Two companies have two CEOs, so there are 102 CEOs in the dataset. We’ve copied the raw data from the LA Times page into a file called raw_compensation.csv . (The page notes that all dollar amounts are in millions of dollars.) In [23]: raw_compensation = Table . read_table( ' raw_compensation.csv ' ) raw_compensation Out[23]: Rank | Name | Company (Headquarters) | Total Pay | % Change 1 | Mark V. Hurd* | Oracle (Redwood City) | $53.25 | (No previous 2 | Safra A. Catz* | Oracle (Redwood City) | $53.24 | (No previous 3 | Robert A. Iger | Walt Disney (Burbank) | $44.91 | -3% 4 | Marissa A. Mayer | Yahoo! (Sunnyvale) | $35.98 | -15% 5 | Marc Benioff | salesforce.com (San Francisco) | $33.36 | -16% 6 | John H. Hammergren | McKesson (San Francisco) | $24.84 | -4% 7 | John S. Watson | Chevron (San Ramon) | $22.04 | -15% 8 | Jeffrey Weiner | LinkedIn (Mountain View) | $19.86 | 27% 9 | John T. Chambers** | Cisco Systems (San Jose) | $19.62 | 19% 10 | John G. Stumpf | Wells Fargo (San Francisco) | $19.32 | -10% ... (92 rows omitted) Question 1. We want to compute the average of the CEOs’ pay. Try running the cell below. In [24]: np . average(raw_compensation . column( "Total Pay" )) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-24-f97fab5a8083> in <module>() ----> 1 np.average(raw_compensation.column("Total Pay")) /srv/app/venv/lib/python3.6/site-packages/numpy/lib/function_base.py in average(a, axis 1126 1127 if weights is None: -> 1128 avg = a.mean(axis) 1129 scl = avg.dtype.type(a.size/avg.size) 1130 else: /srv/app/venv/lib/python3.6/site-packages/numpy/core/_methods.py in _mean(a, axis, dtyp 68 is_float16_result = True 69 2
Image of page 2
---> 70 ret = umr_sum(arr, axis, dtype, out, keepdims) 71 if isinstance(ret, mu.ndarray): 72 ret = um.true_divide( TypeError: cannot perform reduce with flexible type You should see an error. Let’s examine why this error occurred by looking at the values in the "Total Pay" column. Use the type function and set total_pay_type to the type of the first value in the "Total Pay" column.
Image of page 3
Image of page 4

You've reached the end of your free preview.

Want to read all 17 pages?

  • Fall '17
  • Subroutine, Return statement, Total Pay

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