Created
January 17, 2019 08:51
-
-
Save snippsat/8508272b05282620acc7882ff699d0a5 to your computer and use it in GitHub Desktop.
This file contains 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": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>date</th>\n", | |
" <th>day</th>\n", | |
" <th>week</th>\n", | |
" <th>season</th>\n", | |
" <th>team</th>\n", | |
" <th>o:team</th>\n", | |
" <th>site</th>\n", | |
" <th>points</th>\n", | |
" <th>o:points</th>\n", | |
" <th>line</th>\n", | |
" <th>total</th>\n", | |
" <th>OT</th>\n", | |
" <th>SUresult</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>20180909</td>\n", | |
" <td>Sunday</td>\n", | |
" <td>1</td>\n", | |
" <td>2018</td>\n", | |
" <td>Browns</td>\n", | |
" <td>Steelers</td>\n", | |
" <td>home</td>\n", | |
" <td>21</td>\n", | |
" <td>21</td>\n", | |
" <td>4.0</td>\n", | |
" <td>41.0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>20180916</td>\n", | |
" <td>Sunday</td>\n", | |
" <td>2</td>\n", | |
" <td>2018</td>\n", | |
" <td>Browns</td>\n", | |
" <td>Saints</td>\n", | |
" <td>away</td>\n", | |
" <td>18</td>\n", | |
" <td>21</td>\n", | |
" <td>9.0</td>\n", | |
" <td>49.0</td>\n", | |
" <td>0</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>20180920</td>\n", | |
" <td>Thursday</td>\n", | |
" <td>3</td>\n", | |
" <td>2018</td>\n", | |
" <td>Browns</td>\n", | |
" <td>Jets</td>\n", | |
" <td>home</td>\n", | |
" <td>21</td>\n", | |
" <td>17</td>\n", | |
" <td>-3.0</td>\n", | |
" <td>39.5</td>\n", | |
" <td>0</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>20180930</td>\n", | |
" <td>Sunday</td>\n", | |
" <td>4</td>\n", | |
" <td>2018</td>\n", | |
" <td>Browns</td>\n", | |
" <td>Raiders</td>\n", | |
" <td>away</td>\n", | |
" <td>42</td>\n", | |
" <td>45</td>\n", | |
" <td>2.5</td>\n", | |
" <td>45.0</td>\n", | |
" <td>1</td>\n", | |
" <td>0</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>20181007</td>\n", | |
" <td>Sunday</td>\n", | |
" <td>5</td>\n", | |
" <td>2018</td>\n", | |
" <td>Browns</td>\n", | |
" <td>Ravens</td>\n", | |
" <td>home</td>\n", | |
" <td>12</td>\n", | |
" <td>9</td>\n", | |
" <td>2.5</td>\n", | |
" <td>45.5</td>\n", | |
" <td>1</td>\n", | |
" <td>1</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" date day week season team o:team site points o:points \\\n", | |
"0 20180909 Sunday 1 2018 Browns Steelers home 21 21 \n", | |
"1 20180916 Sunday 2 2018 Browns Saints away 18 21 \n", | |
"2 20180920 Thursday 3 2018 Browns Jets home 21 17 \n", | |
"3 20180930 Sunday 4 2018 Browns Raiders away 42 45 \n", | |
"4 20181007 Sunday 5 2018 Browns Ravens home 12 9 \n", | |
"\n", | |
" line total OT SUresult \n", | |
"0 4.0 41.0 1 0 \n", | |
"1 9.0 49.0 0 0 \n", | |
"2 -3.0 39.5 0 1 \n", | |
"3 2.5 45.0 1 0 \n", | |
"4 2.5 45.5 1 1 " | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"import requests\n", | |
"import json\n", | |
"import pandas as pd\n", | |
" \n", | |
"url = \"http://api.sportsdatabase.com/nfl/query.json\"\n", | |
" \n", | |
"sdql = \"date,day,week,season,team,o:team,site,points,o:points,line,total,OT@\"\n", | |
"query = \"season = 2018 and team = Browns and week < 6\"\n", | |
"output = ''\"json\"''\n", | |
"api_key = ''\"guest\"''\n", | |
"string = sdql+query\n", | |
" \n", | |
"querystring = {\"sdql\":string,\"output\":output,\"api_key\":api_key}\n", | |
" \n", | |
"payload = \"\"\n", | |
" \n", | |
"headers = {'User-Agent': 'curl/7.58.0',\n", | |
" 'Accept': '*/*'}\n", | |
" \n", | |
"response = requests.request(\"GET\", url, data=payload, headers=headers, params=querystring)\n", | |
" \n", | |
"temp = response.text[14:-3].replace(\"\\t\", \"\")\n", | |
"temp = temp.replace(\"\\'\", \"\\\"\"\"\")\n", | |
" \n", | |
"data = json.loads(temp)\n", | |
" \n", | |
"d = data\n", | |
" \n", | |
"record = {}\n", | |
"for i in zip(d['headers'], d['groups'][0]['columns']):\n", | |
" record[i[0]] = i[1]\n", | |
" \n", | |
"d = record\n", | |
" \n", | |
"pd.set_option('display.max_columns', None)\n", | |
" \n", | |
"df = pd.DataFrame.from_dict(d)\n", | |
" \n", | |
"df['SUresult'] = df['points'] > df['o:points'] # Add Straight Up results Column and see if team Won SU\n", | |
"df['SUresult'] = df['SUresult'].astype(int) # Change the Dataframe boolan to interger 0 or 1\n", | |
"df" | |
] | |
} | |
], | |
"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.6.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment