Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 54 additions & 9 deletions MLB_rankings.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"name": "MLB_rankings.ipynb",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyPyISm6N8ZsL/NvT4waBFNx",
"include_colab_link": true
},
"kernelspec": {
Expand All @@ -25,7 +24,7 @@
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/RodericGuigoCorominas/datascience/blob/main/MLB_rankings.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
"<a href=\"https://colab.research.google.com/github/liamlewis1030/datascience/blob/main/MLB_rankings.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
Expand All @@ -51,7 +50,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {
"id": "Q1tgUhRoHXxW",
"colab": {
Expand Down Expand Up @@ -298,7 +297,7 @@
},
"outputId": "230be838-1e58-4209-fa99-5b773ccdafb8"
},
"execution_count": 6,
"execution_count": null,
"outputs": [
{
"output_type": "stream",
Expand Down Expand Up @@ -330,7 +329,7 @@
"id": "Vl0ED4h8mIVM",
"outputId": "34f7dc7b-b701-4bfc-d6e4-c3f580e18bf3"
},
"execution_count": 9,
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
Expand All @@ -347,13 +346,59 @@
{
"cell_type": "code",
"source": [
"# your code..."
"from __future__ import print_function\n",
"import numpy as np\n",
"import pandas as pd\n",
"\n",
"url = 'https://raw.githubusercontent.com/RodericGuigoCorominas/datascience/main/datasets/mlb_june_2022.csv'\n",
"df = pd.read_csv(url)\n",
"df\n",
"\n",
"pd.__version__\n",
"all_teams = np.unique(df[['home','visitor']].to_numpy().flatten())\n",
"num_teams = len(all_teams)\n",
"\n",
"print(\"There are\",num_teams,\"teams\")\n",
"print(all_teams)\n",
"\n",
"teams_dict = dict(zip(all_teams, range(num_teams)))"
],
"metadata": {
"id": "h7pqt-a-nfUs"
"id": "h7pqt-a-nfUs",
"outputId": "be48c138-33ea-4877-ef44-61b4ec97b43f",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"execution_count": null,
"outputs": []
"execution_count": 11,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"There are 30 teams\n",
"['Angels' 'Astros' 'Athletics' 'Blue Jays' 'Braves' 'Brewers' 'Cardinals'\n",
" 'Cubs' 'Diamondbacks' 'Dodgers' 'Giants' 'Guardians' 'Mariners' 'Marlins'\n",
" 'Mets' 'Nationals' 'Orioles' 'Padres' 'Phillies' 'Pirates' 'Rangers'\n",
" 'Rays' 'Red Sox' 'Reds' 'Rockies' 'Royals' 'Tigers' 'Twins' 'White Sox'\n",
" 'Yankees']\n",
" home visitor score home score visitor\n",
"0 Cubs Brewers 5 4\n",
"1 Royals Guardians 3 1\n",
"2 Cardinals Pirates 9 0\n",
"3 Nationals Mets 1 5\n",
"4 Braves Reds 3 6\n",
".. ... ... ... ...\n",
"732 Rangers Rays 3 0\n",
"733 Cubs Brewers 8 7\n",
"734 Athletics Astros 1 3\n",
"735 Diamondbacks Braves 8 7\n",
"736 Dodgers Pirates 3 5\n",
"\n",
"[737 rows x 4 columns]\n"
]
}
]
}
]
}
152 changes: 152 additions & 0 deletions pset2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "pset2.py",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyMesRssz4skTykId0NvYhNM",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/liamlewis1030/datascience/blob/main/pset2.py\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "79fdlapYM8cp",
"outputId": "28469436-bf39-4ad7-9c9b-9d00e52dbf85"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Average of a1 = 5.2\n"
]
}
],
"source": [
"def average(l): \n",
" sum=0\n",
" for i in l:\n",
" sum=sum+i\n",
" avg = sum / len(l) \n",
" return avg\n",
" \n",
"a1 = [1,6,3,9,7] \n",
"average(a1) \n",
" \n",
"print(\"Average of a1 =\", average(a1))"
]
},
{
"cell_type": "code",
"source": [
"a1 = [3,0]\n",
"a2 = [6,1,7]\n",
"def common(x,y):\n",
" w=False\n",
" for a in x:\n",
" for b in y:\n",
" print(a,b)\n",
" if a == b:\n",
" print(\"Common element!\")\n",
" w=True\n",
" return w\n",
"common(a1,a2)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "3tRtkucQNJH8",
"outputId": "6e89ce3c-febe-40eb-8864-17b0655d68f4"
},
"execution_count": 68,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"3 6\n",
"3 1\n",
"3 7\n",
"0 6\n",
"0 1\n",
"0 7\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"False"
]
},
"metadata": {},
"execution_count": 68
}
]
},
{
"cell_type": "code",
"source": [
"a1 = [3,7,12,16,-4,6,0,1,0]\n",
"def zerooo(x):\n",
" for a in x:\n",
" if a != 0:\n",
" print(a)\n",
" if a==0:\n",
" print('zerooo')\n",
"zerooo(a1)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "pCTii0kBNJ6u",
"outputId": "6c87d365-8d74-4cb5-9e67-763a57e68863"
},
"execution_count": 95,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"3\n",
"7\n",
"12\n",
"16\n",
"-4\n",
"6\n",
"zerooo\n",
"1\n",
"zerooo\n"
]
}
]
}
]
}