{ "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\" to the \"Average per Movie\"\n", "actors = actors.with_column(\"#1 Movie Impact\", actors.column(\"Gross\") / actors.column(\"Average per Movie\"))\n", "actors.set_format(\"#1 Movie Impact\", NumberFormatter(decimals=1))\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.show(5)" ] }, { "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(5)).show()" ] }, { "cell_type": "code", "execution_count": null, "id": "a1da83b1-ad83-4a74-8f9e-6b7e4874e535", "metadata": {}, "outputs": [], "source": [ "partial_actors.num_rows" ] }, { "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": "0a0c6f6a-d13c-4978-9b9d-499bc502c506", "metadata": {}, "source": [ "How can I 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)" ] } ], "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.12.5" } }, "nbformat": 4, "nbformat_minor": 5 }