{ "cells": [ { "cell_type": "markdown", "id": "3d2b17da-2328-4961-84ce-aad210042017", "metadata": {}, "source": [ "# Chapter 6: 6.3 - 6.4" ] }, { "cell_type": "code", "execution_count": null, "id": "728a799d-fd83-4d56-8653-2794841ab424", "metadata": {}, "outputs": [], "source": [ "from datascience import *\n", "actors = Table.read_table(\"actors.csv\")\n", "actors.show(5)" ] }, { "cell_type": "code", "execution_count": null, "id": "92f44203-ebbb-4973-9d42-113e66c2de9d", "metadata": {}, "outputs": [], "source": [ "# Add a column that calculates the ratio of the \"#1 Movie Impact\" to the \"Total Gross\"\n", "actors = actors.with_column(\"#1 Movie Impact\", actors.column(\"Gross\") / actors.column(\"Total Gross\"))\n", "actors.set_format(\"#1 Movie Impact\", NumberFormatter(decimals=3))\n", "actors.show(5)" ] }, { "cell_type": "markdown", "id": "a8cba2c4-f32c-475c-9b87-330a04703bcd", "metadata": {}, "source": [ "How does one learn about options such as **NumberFormatter**? Use the [documentation](http://www.data8.org/datascience/index.html)!" ] }, { "cell_type": "code", "execution_count": null, "id": "48d2712e-63cb-48ee-8374-4b3810d44364", "metadata": {}, "outputs": [], "source": [ "partial_actors = actors.select(\"Actor\", \"#1 Movie\", \"#1 Movie Impact\").sort(\"#1 Movie Impact\", descending=True)\n", "partial_actors" ] }, { "cell_type": "code", "execution_count": null, "id": "c9518aae-14a2-49cc-8052-dd144492e823", "metadata": {}, "outputs": [], "source": [ "partial_actors.where(\"#1 Movie Impact\", are.above_or_equal_to(.2))" ] }, { "cell_type": "code", "execution_count": null, "id": "fb27fd7b-e294-429a-83de-f66919439384", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "numbers = np.arange(1, partial_actors.num_rows + 1)\n", "numbers" ] }, { "cell_type": "code", "execution_count": null, "id": "9041aea5-753b-4db8-83e0-daf02e4c12c0", "metadata": {}, "outputs": [], "source": [ "# Add an index column to the table\n", "partial_actors = partial_actors.with_column(\"Index\", numbers)\n", "partial_actors.show(5)" ] }, { "cell_type": "code", "execution_count": null, "id": "c3baaade-c820-43f4-a7dd-2005b03fbfa7", "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "partial_actors.plot(\"Index\", \"#1 Movie Impact\")" ] }, { "cell_type": "markdown", "id": "0848c3cd-29e8-4d79-aa61-150dfdde1eae", "metadata": {}, "source": [ "How can one learn more about plot? Use the help function!" ] }, { "cell_type": "code", "execution_count": null, "id": "e1604405-f1fd-471b-b68d-71316db73924", "metadata": {}, "outputs": [], "source": [ "help(partial_actors.plot)" ] }, { "cell_type": "markdown", "id": "fa88e006-0fe7-4eb4-90c1-aa93f5e2289c", "metadata": {}, "source": [ "## Active Learning" ] }, { "cell_type": "markdown", "id": "afe1a128-9c8b-4786-8ce2-fcd75b060c1f", "metadata": {}, "source": [ "1. Display the name of the actor who has the highest Average per Movie \n", "are the smallest values.\n", "2. Explain why this actor is relatively unknown. \n", "3. Suppose you have travelled to Rio de Janiero and are tracking your expenses. \n", "Create a table with the following column of expenses: 20.99, 11.73 and 15.01. \n", "Use the online documentation to format this column to display the marker of Brazilian currency, R$, \n", "in front of each expense when the table is displayed." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.7" } }, "nbformat": 4, "nbformat_minor": 5 }