{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Project: Jupyter Notebook\n", "\n", "## 2. Running Code" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello, Jupyter!\n" ] } ], "source": [ "welcome_message = 'Hello, Jupyter!'\n", "first_cell = True\n", "\n", "if first_cell:\n", " print(welcome_message)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "240.0\n" ] } ], "source": [ "result = 1200 / 5\n", "second_cell = True\n", "\n", "if second_cell:\n", " print(result)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3. Running Code Using the Keyboard" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello, Jupyter!\n", "First cell\n" ] } ], "source": [ "### Shift + Enter; then Alt + Enter ###\n", "\n", "welcome_message = 'Hello, Jupyter!'\n", "first_cell = True\n", "\n", "if first_cell:\n", " print(welcome_message)\n", " \n", "print('First cell')" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Second cell\n" ] } ], "source": [ "### Ctrl + Enter ###\n", "\n", "print('Second cell')" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "240.0\n", "Third cell\n" ] } ], "source": [ "### Ctrl + Enter ###\n", "\n", "result = 1200 / 5\n", "second_cell = True\n", "\n", "if second_cell:\n", " print(result)\n", " \n", "print('Third cell')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 4. Keyboard Shortcuts" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello, Jupyter!\n", "First cell\n" ] } ], "source": [ "welcome_message = 'Hello, Jupyter!'\n", "first_cell = True\n", "\n", "if first_cell:\n", " print(welcome_message)\n", " \n", "print('First cell')" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "240.0\n", "Second cell\n" ] } ], "source": [ "result = 1200 / 5\n", "second_cell = True\n", "\n", "if second_cell:\n", " print(result)\n", " \n", "print('Second cell')" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "A true third cell\n" ] } ], "source": [ "print('A true third cell')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 5. State" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "def welcome(a_string):\n", " print('Welcome to ' + a_string + '!')\n", " \n", "dq = 'Dataquest'\n", "jn = 'Jupyter Notebook'\n", "py = 'Python'" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Welcome to Dataquest!\n", "Welcome to Jupyter Notebook!\n", "Welcome to Python!\n" ] } ], "source": [ "welcome(dq)\n", "welcome(jn)\n", "welcome(py)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 6. Hidden State" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ ">>> welcome_message = 'Hello, Jupyter!'\n", "... first_cell = True\n", "... \n", "... if first_cell:\n", "... print(welcome_message)\n", "...\n", ">>> result = 1200 / 5\n", "... second_cell = True\n", "... \n", "... if second_cell:\n", "... print(result)\n", "...\n", ">>> ### Shift + Enter; then Alt + Enter ###\n", "... \n", "... welcome_message = 'Hello, Jupyter!'\n", "... first_cell = True\n", "... \n", "... if first_cell:\n", "... print(welcome_message)\n", "... \n", "... print('First cell')\n", "...\n", ">>> ### Ctrl + Enter ###\n", "... \n", "... print('Second cell')\n", "...\n", ">>> ### Ctrl + Enter ###\n", "... \n", "... result = 1200 / 5\n", "... second_cell = True\n", "... \n", "... if second_cell:\n", "... print(result)\n", "... \n", "... print('Third cell')\n", "...\n", ">>> welcome_message = 'Hello, Jupyter!'\n", "... first_cell = True\n", "... \n", "... if first_cell:\n", "... print(welcome_message)\n", "... \n", "... print('First cell')\n", "...\n", ">>> result = 1200 / 5\n", "... second_cell = True\n", "... \n", "... if second_cell:\n", "... print(result)\n", "... \n", "... print('Second cell')\n", "...\n", ">>> print('A true third cell')\n", ">>> def welcome(a_string):\n", "... print('Welcome to ' + a_string + '!')\n", "... \n", "... dq = 'Dataquest'\n", "... jn = 'Jupyter Notebook'\n", "... py = 'Python'\n", "...\n", ">>> welcome(dq)\n", "... welcome(jn)\n", "... welcome(py)\n", "...\n", ">>> %history -p\n" ] } ], "source": [ "%history -p" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "# Restart & Clear Output" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\"\\nNote: To reproduce exactly the output in this notebook\\nas whole:\\n\\n1. Run all the cells above.\\n2. Restart the program's state but keep the output\\n(click Restart Kernel).\\n3. Then, run only the cells below.\\n\\n\\n(You were not asked in this exercise to write a note like this.\\nThe note above was written to give more details on how to reproduce\\nthe behavior seen in this notebook.)\\n\"" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'''\n", "Note: To reproduce exactly the output in this notebook\n", "as whole:\n", "\n", "1. Run all the cells above.\n", "2. Restart the program's state but keep the output\n", "(click Restart Kernel).\n", "3. Then, run only the cells below.\n", "\n", "\n", "(You were not asked in this exercise to write a note like this.\n", "The note above was written to give more details on how to reproduce\n", "the behavior seen in this notebook.)\n", "'''" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ ">>> welcome_message = 'Hello, Jupyter!'\n", "... first_cell = True\n", "... \n", "... if first_cell:\n", "... print(welcome_message)\n", "...\n", ">>> result = 1200 / 5\n", "... second_cell = True\n", "... \n", "... if second_cell:\n", "... print(result)\n", "...\n", ">>> ### Shift + Enter; then Alt + Enter ###\n", "... \n", "... welcome_message = 'Hello, Jupyter!'\n", "... first_cell = True\n", "... \n", "... if first_cell:\n", "... print(welcome_message)\n", "... \n", "... print('First cell')\n", "...\n", ">>> ### Ctrl + Enter ###\n", "... \n", "... print('Second cell')\n", "...\n", ">>> ### Ctrl + Enter ###\n", "... \n", "... result = 1200 / 5\n", "... second_cell = True\n", "... \n", "... if second_cell:\n", "... print(result)\n", "... \n", "... print('Third cell')\n", "...\n", ">>> welcome_message = 'Hello, Jupyter!'\n", "... first_cell = True\n", "... \n", "... if first_cell:\n", "... print(welcome_message)\n", "... \n", "... print('First cell')\n", "...\n", ">>> result = 1200 / 5\n", "... second_cell = True\n", "... \n", "... if second_cell:\n", "... print(result)\n", "... \n", "... print('Second cell')\n", "...\n", ">>> print('A true third cell')\n", ">>> def welcome(a_string):\n", "... print('Welcome to ' + a_string + '!')\n", "... \n", "... dq = 'Dataquest'\n", "... jn = 'Jupyter Notebook'\n", "... py = 'Python'\n", "...\n", ">>> welcome(dq)\n", "... welcome(jn)\n", "... welcome(py)\n", "...\n", ">>> %history -p\n", ">>> # Restart & Clear Output\n", ">>> '''\n", "... Note: To reproduce exactly the output in this notebook\n", "... as whole:\n", "... \n", "... 1. Run all the cells above.\n", "... 2. Restart the program's state but keep the output\n", "... (click Restart Kernel).\n", "... 3. Then, run only the cells below.\n", "... \n", "... \n", "... (You were not asked in this exercise to write a note like this.\n", "... The note above was written to give more details on how to reproduce\n", "... the behavior seen in this notebook.)\n", "... '''\n", "...\n", ">>> %history -p\n" ] } ], "source": [ "%history -p" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "def welcome(a_string):\n", " welcome_msg = 'Welcome to ' + a_string + '!'\n", " return welcome_msg\n", "\n", "dq = 'Dataquest'\n", "jn = 'Jupyter Notebook'" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Welcome to Python!'" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "welcome(dq)\n", "welcome(jn)\n", "welcome(py)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ ">>> welcome_message = 'Hello, Jupyter!'\n", "... first_cell = True\n", "... \n", "... if first_cell:\n", "... print(welcome_message)\n", "...\n", ">>> result = 1200 / 5\n", "... second_cell = True\n", "... \n", "... if second_cell:\n", "... print(result)\n", "...\n", ">>> ### Shift + Enter; then Alt + Enter ###\n", "... \n", "... welcome_message = 'Hello, Jupyter!'\n", "... first_cell = True\n", "... \n", "... if first_cell:\n", "... print(welcome_message)\n", "... \n", "... print('First cell')\n", "...\n", ">>> ### Ctrl + Enter ###\n", "... \n", "... print('Second cell')\n", "...\n", ">>> ### Ctrl + Enter ###\n", "... \n", "... result = 1200 / 5\n", "... second_cell = True\n", "... \n", "... if second_cell:\n", "... print(result)\n", "... \n", "... print('Third cell')\n", "...\n", ">>> welcome_message = 'Hello, Jupyter!'\n", "... first_cell = True\n", "... \n", "... if first_cell:\n", "... print(welcome_message)\n", "... \n", "... print('First cell')\n", "...\n", ">>> result = 1200 / 5\n", "... second_cell = True\n", "... \n", "... if second_cell:\n", "... print(result)\n", "... \n", "... print('Second cell')\n", "...\n", ">>> print('A true third cell')\n", ">>> def welcome(a_string):\n", "... print('Welcome to ' + a_string + '!')\n", "... \n", "... dq = 'Dataquest'\n", "... jn = 'Jupyter Notebook'\n", "... py = 'Python'\n", "...\n", ">>> welcome(dq)\n", "... welcome(jn)\n", "... welcome(py)\n", "...\n", ">>> %history -p\n", ">>> # Restart & Clear Output\n", ">>> '''\n", "... Note: To reproduce exactly the output in this notebook\n", "... as whole:\n", "... \n", "... 1. Run all the cells above.\n", "... 2. Restart the program's state but keep the output\n", "... (click Restart Kernel).\n", "... 3. Then, run only the cells below.\n", "... \n", "... \n", "... (You were not asked in this exercise to write a note like this.\n", "... The note above was written to give more details on how to reproduce\n", "... the behavior seen in this notebook.)\n", "... '''\n", "...\n", ">>> %history -p\n", ">>> def welcome(a_string):\n", "... welcome_msg = 'Welcome to ' + a_string + '!'\n", "... return welcome_msg\n", "... \n", "... dq = 'Dataquest'\n", "... jn = 'Jupyter Notebook'\n", "...\n", ">>> welcome(dq)\n", "... welcome(jn)\n", "... welcome(py)\n", "...\n", ">>> %history -p\n" ] } ], "source": [ "%history -p" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Welcome to Python!'" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "welcome(dq)\n", "welcome(jn)\n", "welcome(py)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 7. Text and Markdown" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the code cell below, we:\n", "\n", "- Open the `AppleStore.csv` file using the `open()` function, and assign the output to a variable named `opened_file`\n", "- Import the `reader()` function from the `csv` module\n", "- Read in the opened file using the `reader()` function, and assign the output to a variable named `read_file`\n", "- Transform the read-in file to a list of lists using `list()` and save it to a variable named `apps_data`\n", "- Display the header row and the first three rows of the data set." ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[['id',\n", " 'track_name',\n", " 'size_bytes',\n", " 'currency',\n", " 'price',\n", " 'rating_count_tot',\n", " 'rating_count_ver',\n", " 'user_rating',\n", " 'user_rating_ver',\n", " 'ver',\n", " 'cont_rating',\n", " 'prime_genre',\n", " 'sup_devices.num',\n", " 'ipadSc_urls.num',\n", " 'lang.num',\n", " 'vpp_lic'],\n", " ['284882215',\n", " 'Facebook',\n", " '389879808',\n", " 'USD',\n", " '0.0',\n", " '2974676',\n", " '212',\n", " '3.5',\n", " '3.5',\n", " '95.0',\n", " '4+',\n", " 'Social Networking',\n", " '37',\n", " '1',\n", " '29',\n", " '1'],\n", " ['389801252',\n", " 'Instagram',\n", " '113954816',\n", " 'USD',\n", " '0.0',\n", " '2161558',\n", " '1289',\n", " '4.5',\n", " '4.0',\n", " '10.23',\n", " '12+',\n", " 'Photo & Video',\n", " '37',\n", " '0',\n", " '29',\n", " '1'],\n", " ['529479190',\n", " 'Clash of Clans',\n", " '116476928',\n", " 'USD',\n", " '0.0',\n", " '2130805',\n", " '579',\n", " '4.5',\n", " '4.5',\n", " '9.24.12',\n", " '9+',\n", " 'Games',\n", " '38',\n", " '5',\n", " '18',\n", " '1']]" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "opened_file = open('AppleStore.csv')\n", "from csv import reader\n", "read_file = reader(opened_file)\n", "apps_data = list(read_file)\n", "\n", "apps_data[:4]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The data set above contains information about more than 7000 Apple iOS mobile apps. The data was collected from the iTunes Search API by data engineer [Ramanathan Perumal](https://www.kaggle.com/ramamet4). Documentation for the data set can be found [at this page](https://www.kaggle.com/ramamet4/app-store-apple-data-set-10k-apps/home), where you'll also be able to download the data set.\n", "\n", "This is a table explaining what each column in the data set describes:\n", "\n", "Column name | Description\n", "-- | --\n", "\"id\" | App ID\n", "\"track_name\"| App Name\n", "\"size_bytes\"| Size (in Bytes)\n", "\"currency\"| Currency Type\n", "\"price\"| Price amount\n", "\"rating_count_tot\"| User Rating counts (for all version)\n", "\"rating_count_ver\"| User Rating counts (for current version)\n", "\"user_rating\" | Average User Rating value (for all version)\n", "\"user_rating_ver\"| Average User Rating value (for current version)\n", "\"ver\" | Latest version code\n", "\"cont_rating\"| Content Rating\n", "\"prime_genre\"| Primary Genre\n", "\"sup_devices.num\"| Number of supporting devices\n", "\"ipadSc_urls.num\"| Number of screenshots showed for display\n", "\"lang.num\"| Number of supported languages\n", "\"vpp_lic\"| Vpp Device Based Licensing Enabled" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.8.2" } }, "nbformat": 4, "nbformat_minor": 2 }