Last active
July 17, 2023 15:10
-
-
Save misterhay/4e931474e69769b89f0489ace4165623 to your computer and use it in GitHub Desktop.
Notebook for a turtles and data science hackathon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "attachments": {}, | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "\n", | |
| "\n", | |
| "<a href=\"https://hub.callysto.ca/jupyter/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgist.github.com%2F4e931474e69769b89f0489ace4165623.git&branch=main&urlpath=notebooks/4e931474e69769b89f0489ace4165623.git/turtle-ds-hackathon.ipynb&depth=1\" target=\"_parent\"><img src=\"https://raw.githubusercontent.com/callysto/curriculum-notebooks/master/open-in-callysto-button.svg?sanitize=true\" width=\"123\" height=\"24\" alt=\"Open in Callysto\"></a>" | |
| ] | |
| }, | |
| { | |
| "attachments": {}, | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "# Turtle and Data Science Hackathon Notebook\n", | |
| "\n", | |
| "Team Name: \n", | |
| "\n", | |
| "School: " | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "## Introduction\n", | |
| "\n", | |
| "[Turtle graphics](https://en.wikipedia.org/wiki/Turtle_graphics) have been used for learning about programming and computational thinking. We will use them as a fun way to learn about [Python](https://www.python.org) programming and [Jupyter notebooks](https://jupyter.org).\n", | |
| "\n", | |
| "## Turtle Commands\n", | |
| "\n", | |
| "Click on the code cell below, then click the `▶Run` button to run the Python code. It will import `Turtle` from the [mobilechelonian]((https://github.com/takluyver/mobilechelonian)) library, then create a new turtle drawing canvas." | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "from mobilechelonian import Turtle\n", | |
| "t = Turtle()\n", | |
| "t.speed(10)\n", | |
| "t.forward(50)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "Assuming that your turtle is named `t`, here are the possible commands you can use.\n", | |
| "\n", | |
| "|Command|Description|Example|\n", | |
| "|-|-|-|\n", | |
| "|`t.speed(integer)`|speed of your turtle, from 1 to 10|`t.speed(10)`|\n", | |
| "|`t.right(degrees)`|turn turtle right a certain number of degrees|`t.right(90)`|\n", | |
| "|`t.left(degrees)`|turn turtle left a certain number of degrees|`t.left(45)`|\n", | |
| "|`t.forward(units)`|move your turtle forward a certain number of pixels|`t.forward(100)`|\n", | |
| "|`t.backward(units)`|move your turtle backward a certain number of pixels|`t.backward(20)`|\n", | |
| "|`t.circle(r, degrees)`|have your turtle draw a piece of a circle of radius r, through some number of degrees|`t.circle(40, 360)`|\n", | |
| "|`t.penup()`|now your turtle can move without drawing lines|`t.penup()`|\n", | |
| "|`t.pendown()`|make your turtle draw lines again|`t.pendown()`|\n", | |
| "|`t.pencolor('color')`|color of your turtle’s line using a [color name](https://www.w3schools.com/colors/colors_names.asp)|`t.pencolor('blue')`|\n", | |
| "|`t.pencolor('rgb(R, G, B)')`|color of your turtle’s line using red, green, and blue values from 0 to 255|`t.pencolor('rgb(0, 255, 100)')`|\n", | |
| "|`t.setposition(x, y)`|move the turtle to a specific position. (0,0) is the top left and (400, 400) is the bottom right|`t.setposition(100, 250)`|\n", | |
| "|`t.home()`|move the turtle back to the center of the screen|`t.home()`|\n", | |
| "|`t.setbearing(degrees)`|set the turtle’s heading to a specific number of degrees|`t.setheading(90)`|\n", | |
| "\n", | |
| "For inspiration you can check out [this example](https://github.com/callysto/TMTeachingTurtles/blob/jupyter-turtles-art-contest/turtles-cool-art-demo.ipynb).\n", | |
| "\n", | |
| "The challenges below do not need to be completed in a particular order. Notify a supervisor when you have accomplished one so they can award you points." | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "## Beginner Challenges\n", | |
| "\n", | |
| "These challenges are worth 2 points each.\n", | |
| "\n", | |
| "1. draw a red rectangle" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "2. draw a green triangle" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "3. draw a blue circle" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "4. draw a purple pentagon" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "5. draw a yellow star" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "6. draw a cyan arrow" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "7. draw an orange parallelogram" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "8. draw a magenta hexagon" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "9. draw a face" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "10. draw the symbol π" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "## Intermediate Challenges\n", | |
| "\n", | |
| "These challenges are worth 5 points each.\n", | |
| "\n", | |
| "1. draw a pink heart" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "2. draw a Venn diagram" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "3. draw a right angle triangle with the RGB color `(205, 133, 63)`" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "4. draw an equilateral triangle with a perimeter of 90 pixels" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "5. draw a semi-circle with two different colors" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "6. draw a silver crescent" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "7. draw Pac-Man: [click here](https://en.wikipedia.org/wiki/Pac-Man)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "8. draw a house like this:\n", | |
| "\n", | |
| "" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "9. draw a house with a door, a window, a chimney and a background scene" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "10. draw a simple black flower like this:\n", | |
| "\n", | |
| "" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n", | |
| "\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "11. draw a black flower like this:\n", | |
| "\n", | |
| "" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "12. use [loops](https://www.w3schools.com/python/python_for_loops.asp) in a drawing.\n", | |
| "\n", | |
| "---\n", | |
| "*Code Help: Example of how to use a loop in Python*\n", | |
| "\n", | |
| "```\n", | |
| "for i in range(4): # lines that are indented are part of the loop\n", | |
| " t.forward(100)\n", | |
| " t.left(90)\n", | |
| "```\n", | |
| "---" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "13. use [nested loops](https://www.w3schools.com/python/gloss_python_for_nested.asp), which are loops within loops, in a drawing" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "14. use [functions](https://www.w3schools.com/python/python_functions.asp) in a drawing\n", | |
| "\n", | |
| "---\n", | |
| "*Code Help: Example of how to use a function in Python*\n", | |
| "```\n", | |
| "# define a function to draw a square, use the above code\n", | |
| "def square():\n", | |
| " for i in range(4):\n", | |
| " t.forward(100)\n", | |
| " t.left(90)\n", | |
| "\n", | |
| "# call the function to draw a square, no need to indent\n", | |
| "square()\n", | |
| "t.right(90)\n", | |
| "square()\n", | |
| "t.right(90)\n", | |
| "```\n", | |
| "---" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "15. draw an emoji" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "16. complete this [Callysto survey](https://docs.google.com/forms/d/e/1FAIpQLSd0Ih8x_dHS1FDfw4WYwcZAirwagfkbqoB9_WO1XoV5WqAi3Q/viewform) and show the \"form submitted\" page to a supervisor" | |
| ] | |
| }, | |
| { | |
| "attachments": {}, | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "## Advanced Challenges\n", | |
| "\n", | |
| "These challenges are worth 15 points each.\n", | |
| "\n", | |
| "1. draw a pointy coloured flower like this:\n", | |
| "\n", | |
| "" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "2. draw a **full** maple leaf using the code below as a starting point" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n", | |
| "\n", | |
| "def half_leaf():\n", | |
| " t.penup()\n", | |
| " t.setposition(200,200)\n", | |
| " t.pendown()\n", | |
| " \n", | |
| " t.left(90)\n", | |
| " t.forward(50)\n", | |
| "\n", | |
| " t.right(100)\n", | |
| " t.forward(50)\n", | |
| "\n", | |
| " t.left(130)\n", | |
| " t.forward(20)\n", | |
| "\n", | |
| " t.right(90)\n", | |
| " t.forward(50)\n", | |
| "\n", | |
| " t.left(100)\n", | |
| " t.forward(15)\n", | |
| "\n", | |
| " t.right(80)\n", | |
| " t.forward(30)\n", | |
| "\n", | |
| " t.left(130)\n", | |
| " t.forward(30)\n", | |
| "\n", | |
| " t.right(90)\n", | |
| " t.forward(15)\n", | |
| "\n", | |
| " t.left(120)\n", | |
| " t.forward(40)\n", | |
| "\n", | |
| " t.right(120)\n", | |
| " t.forward(50)\n", | |
| "\n", | |
| " t.left(120)\n", | |
| " t.forward(15)\n", | |
| "\n", | |
| " t.right(90)\n", | |
| " t.forward(30)\n", | |
| "\n", | |
| "color_list = ['red', 'orange', 'yellow', 'green', 'blue', 'violet']\n", | |
| "\n", | |
| "for color in color_list:\n", | |
| " t.pencolor(color)\n", | |
| " half_leaf()\n", | |
| " t.right(60)\n", | |
| "\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "3. draw a landscape scene with multiple colours" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "4. write your name or nickname with a turtle" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "5. draw a one-octave piano keyboard" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "### Advanced Data Science Challenges Introduction\n", | |
| "\n", | |
| "Click on the code cell below, then click the `▶Run` button to import the [pandas](https://pandas.pydata.org) library and some made-up data from a pet adoption facility." | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "import pandas as pd\n", | |
| "pets = pd.read_csv('https://raw.githubusercontent.com/callysto/hackathon/master/PrepMaterials/pets.csv')\n", | |
| "pets" | |
| ] | |
| }, | |
| { | |
| "attachments": {}, | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "The `.shape` command shows the number of rows and columns." | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "pets.shape" | |
| ] | |
| }, | |
| { | |
| "attachments": {}, | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "The `.columns` command shows the number of rows and columns." | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "pets.columns" | |
| ] | |
| }, | |
| { | |
| "attachments": {}, | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "We can select and display just one column using square brackets." | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "pets[['Species']]" | |
| ] | |
| }, | |
| { | |
| "attachments": {}, | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "You can select multiple columns by separating the column names with commas." | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "pets[['Species','Gender']]" | |
| ] | |
| }, | |
| { | |
| "attachments": {}, | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "By default, `.head()` displays the first 5 rows.\n", | |
| "\n", | |
| "You can also try things like:\n", | |
| "\n", | |
| "`.head(10)`\n", | |
| "\n", | |
| "`.tail(2)`\n", | |
| "\n", | |
| "`.tail(17)`" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "pets.head()" | |
| ] | |
| }, | |
| { | |
| "attachments": {}, | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "## Advanced Data Science Challenges\n", | |
| "\n", | |
| "These challenges are also worth 15 points each.\n", | |
| "\n", | |
| "6. Basic operations: after running the code cells above:\n", | |
| " * in the cell below, uncomment the code (remove the `#` sign)\n", | |
| " * change \"column1\", \"column2\", and \"column3\" to \"Species\", \"Fixed\", and \"Time to Adoption (weeks)\" to get these 3 columns\n", | |
| " * `▶Run` the cell to display the data" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "#pets[[\"column1\",\"column2\",\"column3\"]]" | |
| ] | |
| }, | |
| { | |
| "attachments": {}, | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "* You can filter the data, for example to show only dogs, using `pets[\"Column\"] == \"something\"`. For example, `pets[pets[\"Species\"] == \"dog\"]`.\n", | |
| "* Note that the `==` sign means \"check if it is equal to\" rather than asigning a value to a variable.\n", | |
| "* You can also use \"is not equal to\" `!=`, for example `pets[pets[\"Species\"] != \"dog\"]`\n", | |
| "* If you want two or more conditions, use the `&` symbol and put each condition in parenthesis, for example `pets[ (pets[\"Gender\"]==\"female\") & (pets[\"Age (years)\"]>3) ]`\n", | |
| "* To use \"or\" instead of \"and\", use the `|` symbol, for example `pets[ (pets[\"Fixed\"]==True) | (pets[\"Legs\"]>4) ]`\n", | |
| "\n", | |
| "7. Select or filter data from columns by condition\n", | |
| " * In the cell below, uncomment the code (remove the `#` sign)\n", | |
| " * Change the cell below to get a subset of the data where \"Fixed\" is equal to True **and** \"Time to Adoption (weeks)\" is less than 5\n", | |
| " * Click the `▶Run` button to display the data" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "#pets[ (pets[\"\"] == 0) | (pets[\"\"] == 0) ]" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "* You can sort data in the dataframe, for example `pets.sort_values('Age (years)')`\n", | |
| "* By default it sort in ascending order (smallest to largest), but you can change that, for example `pets.sort_values('Age (years)', ascending=False)`\n", | |
| "* You can also sort by multple columns, for example to sort by age and then by time to adoption: `pets.sort_values(['Age (years)','Time to Adoption (weeks)'])`\n", | |
| "\n", | |
| "8. Sorting data\n", | |
| " * Write code below to sort the pets dataframe by age and species\n", | |
| " * Click the `▶Run` button to display the data" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "attachments": {}, | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "9. Create a visualization from the pets dataframe\n", | |
| " * Use this [**link**](https://github.com/callysto/data-science-and-artificial-intelligence/blob/main/04-visualizations.ipynb) to view the different types of visualizations and code examples to create your **own** visualizations from the pets data.\n", | |
| " * You can get points for each of the following visualiization types." | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "import plotly.express as px\n", | |
| "import pandas as pd\n", | |
| "pd.read_csv('https://raw.githubusercontent.com/callysto/hackathon/master/PrepMaterials/pets.csv')" | |
| ] | |
| }, | |
| { | |
| "attachments": {}, | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "### Bar Graph" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "\n" | |
| ] | |
| }, | |
| { | |
| "attachments": {}, | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "### Line Graph" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "attachments": {}, | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "### Scatter Plot" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "attachments": {}, | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "### Pie Chart" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "10. Use a [dataframe to create a turtle drawing](https://github.com/callysto/TMTeachingTurtles/blob/master/TMDataTurtles/turtles-and-data-student.ipynb)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "deletable":false, | |
| "editable":true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "import pandas as pd\n", | |
| "df = pd.read_csv('https://raw.githubusercontent.com/callysto/hackathon/master/HackathonNotebooks/Turtles/turtles-drawings.csv')\n", | |
| "\n", | |
| "t = Turtle()\n", | |
| "t.speed(10)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "11. Use [this form](https://forms.gle/fUwREoMutHLWdwb47) to submit your:\n", | |
| "* Team name\n", | |
| "* Team member name(s)\n", | |
| "* Answers to the reflection questions:\n", | |
| " 1. What are two things you have learned during this hackathon?\n", | |
| " 1. Which visualization or artwork do you consider your best, and why?\n", | |
| " 1. What was the most challenging obstacle you encountered and successfully overcame during the hackathon?" | |
| ] | |
| }, | |
| { | |
| "attachments": {}, | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "deletable":false, | |
| "editable":false | |
| }, | |
| "source": [ | |
| "[](https://github.com/callysto/curriculum-notebooks/blob/master/LICENSE.md)" | |
| ] | |
| } | |
| ], | |
| "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.10.6" | |
| }, | |
| "vscode": { | |
| "interpreter": { | |
| "hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6" | |
| } | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 4 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment