{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"2020-11-05 - class #10 - activities.ipynb","provenance":[],"collapsed_sections":["8d6J9xZiFtU2","II3iXc9lS-Xb"]},"kernelspec":{"name":"python3","display_name":"Python 3"}},"cells":[{"cell_type":"markdown","metadata":{"id":"BRAp37uklN9X"},"source":["# Class \\#10 activities"]},{"cell_type":"markdown","metadata":{"id":"75Fru6pykhxR"},"source":["# Practice with `pandas`: Ballard Locks salmon counts"]},{"cell_type":"code","metadata":{"id":"XANgNomokhQp","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1604626782369,"user_tz":480,"elapsed":412,"user":{"displayName":"Ethan C Campbell","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GjCBYTiuomqOsCakND1k_5wj0kYvFY53Jt7kunt=s64","userId":"11255944928409084259"}},"outputId":"ca4d09ea-e99e-4779-9eab-8baf33447421"},"source":["# Import NumPy, Pandas, Matplotlib, and datetime at the top of your code\n","import numpy as np\n","import pandas as pd\n","import matplotlib.pyplot as plt\n","from datetime import datetime, timedelta\n","\n","# Give Colab access to Google Drive\n","from google.colab import drive\n","drive.mount('/content/drive')"],"execution_count":null,"outputs":[{"output_type":"stream","text":["Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"c258zxyZlOuk"},"source":["# Filepath for Ballard Locks salmon count data\n","\n","# Note: you may need to change this to match your own filepath,\n","# which you can get by opening the left sidebar (folder icon),\n","# navigating to the file, clicking the \"...\" on the file, and\n","# selecting \"Copy path\"\n","filepath = '/content/drive/My Drive/OCEAN 215 - Autumn \\'20/OCEAN 215 - Autumn \\'20 - Course documents/Zoom class slides and notebooks/2020-11-05 - class #10 - data/ballard_salmon_counts.csv'"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"eQCX7qkNSpUB"},"source":["## **Breakout rooms, round 1**"]},{"cell_type":"markdown","metadata":{"id":"arXwiCsM6wL1"},"source":["0. Assign roles:\n","> * **Choose one person to write code and share their screen.**\n","> * **Choose a second person to take notes on the answers to report back to the class.**\n","1. Load the salmon data CSV file into Pandas.\n","> * When you do this, specify that the 0th column (the dates) should be the index.\n",">\n","> * Also specify that Pandas should parse the index as dates (datetimes).\n",">\n","> * Consult the documentation for [`pd.read_csv()`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html) to find the arguments to specify these two things.\n","2. Display the data.\n","3. Use `.describe()` to view the summary statistics.\n","4. Answer the following questions with your group:\n","\n","* How many salmon species are counted?\n","* When does this data start and end?\n","* What are the average daily counts for each species?\n","* What are the highest daily counts for each species?"]},{"cell_type":"code","metadata":{"id":"I93RpkPttjHH","colab":{"base_uri":"https://localhost:8080/","height":708},"executionInfo":{"status":"ok","timestamp":1604626785489,"user_tz":480,"elapsed":369,"user":{"displayName":"Ethan C Campbell","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GjCBYTiuomqOsCakND1k_5wj0kYvFY53Jt7kunt=s64","userId":"11255944928409084259"}},"outputId":"601bfea5-e38c-408e-ccee-95d31ebe780b"},"source":["# Load the float data file from Google Drive as a Pandas DataFrame\n","salmon_data = pd.read_csv(filepath,index_col=0,parse_dates=True)\n","\n","# View data and stats\n","display(salmon_data)\n","salmon_data.describe()\n","\n","# Answers:\n","# a. 3 species\n","# b. June 2013 to October 2020\n","# c. 242, 247, 1316 for Chinook, Coho, Sockeye\n","# d. 916, 1026, 12936"],"execution_count":null,"outputs":[{"output_type":"display_data","data":{"text/html":["
\n"," | Chinook | \n","Coho | \n","Sockeye | \n","
---|---|---|---|
2013-06-12 | \n","NaN | \n","NaN | \n","2778.0 | \n","
2013-06-13 | \n","NaN | \n","NaN | \n","2424.0 | \n","
2013-06-14 | \n","NaN | \n","NaN | \n","1285.0 | \n","
2013-06-15 | \n","NaN | \n","NaN | \n","2430.0 | \n","
2013-06-16 | \n","NaN | \n","NaN | \n","3081.0 | \n","
... | \n","... | \n","... | \n","... | \n","
2020-09-28 | \n","NaN | \n","219.0 | \n","NaN | \n","
2020-09-29 | \n","NaN | \n","81.0 | \n","NaN | \n","
2020-09-30 | \n","NaN | \n","13.0 | \n","NaN | \n","
2020-10-01 | \n","NaN | \n","44.0 | \n","NaN | \n","
2020-10-02 | \n","NaN | \n","38.0 | \n","NaN | \n","
419 rows × 3 columns
\n","\n"," | Chinook | \n","Coho | \n","Sockeye | \n","
---|---|---|---|
count | \n","55.000000 | \n","32.000000 | \n","370.000000 | \n","
mean | \n","224.290909 | \n","246.718750 | \n","1315.670270 | \n","
std | \n","218.044395 | \n","238.581052 | \n","1746.660107 | \n","
min | \n","0.000000 | \n","13.000000 | \n","0.000000 | \n","
25% | \n","59.000000 | \n","75.750000 | \n","159.250000 | \n","
50% | \n","164.000000 | \n","154.500000 | \n","699.000000 | \n","
75% | \n","305.000000 | \n","378.500000 | \n","1745.000000 | \n","
max | \n","916.000000 | \n","1026.000000 | \n","12936.000000 | \n","