Skip to content

Instantly share code, notes, and snippets.

@snippsat
Created November 24, 2019 13:48
Show Gist options
  • Save snippsat/80ddc88eeb253da8fc19bf4e39fbd921 to your computer and use it in GitHub Desktop.
Save snippsat/80ddc88eeb253da8fc19bf4e39fbd921 to your computer and use it in GitHub Desktop.
{
"cells": [
{
"cell_type": "code",
"execution_count": 6,
"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>Pos.</th>\n",
" <th>Club</th>\n",
" <th>Seasons</th>\n",
" <th>Pld</th>\n",
" <th>Win</th>\n",
" <th>Draw</th>\n",
" <th>Loss</th>\n",
" <th>GF</th>\n",
" <th>GA</th>\n",
" <th>GD</th>\n",
" <th>Pts</th>\n",
" <th>1st</th>\n",
" <th>2nd</th>\n",
" <th>3rd</th>\n",
" <th>4th</th>\n",
" <th>Relegated</th>\n",
" <th>BestPos.</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>Manchester United</td>\n",
" <td>27</td>\n",
" <td>1038</td>\n",
" <td>648</td>\n",
" <td>224</td>\n",
" <td>166</td>\n",
" <td>1989</td>\n",
" <td>929</td>\n",
" <td>1060</td>\n",
" <td>2168</td>\n",
" <td>13.0</td>\n",
" <td>6.0</td>\n",
" <td>3.0</td>\n",
" <td>1.0</td>\n",
" <td>NaN</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" <td>Arsenal</td>\n",
" <td>27</td>\n",
" <td>1038</td>\n",
" <td>565</td>\n",
" <td>260</td>\n",
" <td>213</td>\n",
" <td>1845</td>\n",
" <td>1013</td>\n",
" <td>832</td>\n",
" <td>1955</td>\n",
" <td>3.0</td>\n",
" <td>6.0</td>\n",
" <td>5.0</td>\n",
" <td>7.0</td>\n",
" <td>NaN</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3</td>\n",
" <td>Chelsea</td>\n",
" <td>27</td>\n",
" <td>1038</td>\n",
" <td>558</td>\n",
" <td>257</td>\n",
" <td>223</td>\n",
" <td>1770</td>\n",
" <td>1002</td>\n",
" <td>768</td>\n",
" <td>1931</td>\n",
" <td>5.0</td>\n",
" <td>4.0</td>\n",
" <td>5.0</td>\n",
" <td>2.0</td>\n",
" <td>NaN</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>4</td>\n",
" <td>Liverpool</td>\n",
" <td>27</td>\n",
" <td>1038</td>\n",
" <td>529</td>\n",
" <td>262</td>\n",
" <td>247</td>\n",
" <td>1774</td>\n",
" <td>1046</td>\n",
" <td>728</td>\n",
" <td>1849</td>\n",
" <td>NaN</td>\n",
" <td>4.0</td>\n",
" <td>5.0</td>\n",
" <td>7.0</td>\n",
" <td>NaN</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>5</td>\n",
" <td>Tottenham Hotspur</td>\n",
" <td>27</td>\n",
" <td>1038</td>\n",
" <td>446</td>\n",
" <td>257</td>\n",
" <td>335</td>\n",
" <td>1547</td>\n",
" <td>1306</td>\n",
" <td>241</td>\n",
" <td>1595</td>\n",
" <td>NaN</td>\n",
" <td>1.0</td>\n",
" <td>2.0</td>\n",
" <td>3.0</td>\n",
" <td>NaN</td>\n",
" <td>2</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Pos. Club Seasons Pld Win Draw Loss GF GA GD \\\n",
"0 1 Manchester United 27 1038 648 224 166 1989 929 1060 \n",
"1 2 Arsenal 27 1038 565 260 213 1845 1013 832 \n",
"2 3 Chelsea 27 1038 558 257 223 1770 1002 768 \n",
"3 4 Liverpool 27 1038 529 262 247 1774 1046 728 \n",
"4 5 Tottenham Hotspur 27 1038 446 257 335 1547 1306 241 \n",
"\n",
" Pts 1st 2nd 3rd 4th Relegated BestPos. \n",
"0 2168 13.0 6.0 3.0 1.0 NaN 1 \n",
"1 1955 3.0 6.0 5.0 7.0 NaN 1 \n",
"2 1931 5.0 4.0 5.0 2.0 NaN 1 \n",
"3 1849 NaN 4.0 5.0 7.0 NaN 2 \n",
"4 1595 NaN 1.0 2.0 3.0 NaN 2 "
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"\n",
"df = pd.read_html('https://en.wikipedia.org/wiki/Premier_League_records_and_statistics', match='Seasons')\n",
"df = df[0]\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Pos. int64\n",
"Club object\n",
"Seasons int64\n",
"Pld int64\n",
"Win int64\n",
"Draw int64\n",
"Loss int64\n",
"GF int64\n",
"GA int64\n",
"GD object\n",
"Pts object\n",
"1st float64\n",
"2nd float64\n",
"3rd float64\n",
"4th float64\n",
"Relegated float64\n",
"BestPos. int64\n",
"dtype: object"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Look at types,most is good b\n",
"df.dtypes"
]
},
{
"cell_type": "code",
"execution_count": 17,
"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>Pos.</th>\n",
" <th>Club</th>\n",
" <th>Seasons</th>\n",
" <th>Pld</th>\n",
" <th>Win</th>\n",
" <th>Draw</th>\n",
" <th>Loss</th>\n",
" <th>GF</th>\n",
" <th>GA</th>\n",
" <th>GD</th>\n",
" <th>Pts</th>\n",
" <th>1st</th>\n",
" <th>2nd</th>\n",
" <th>3rd</th>\n",
" <th>4th</th>\n",
" <th>Relegated</th>\n",
" <th>BestPos.</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>Manchester United</td>\n",
" <td>27</td>\n",
" <td>1038</td>\n",
" <td>648</td>\n",
" <td>224</td>\n",
" <td>166</td>\n",
" <td>1989</td>\n",
" <td>929</td>\n",
" <td>1060</td>\n",
" <td>2168</td>\n",
" <td>13.0</td>\n",
" <td>6.0</td>\n",
" <td>3.0</td>\n",
" <td>1.0</td>\n",
" <td>NaN</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" <td>Arsenal</td>\n",
" <td>27</td>\n",
" <td>1038</td>\n",
" <td>565</td>\n",
" <td>260</td>\n",
" <td>213</td>\n",
" <td>1845</td>\n",
" <td>1013</td>\n",
" <td>832</td>\n",
" <td>1955</td>\n",
" <td>3.0</td>\n",
" <td>6.0</td>\n",
" <td>5.0</td>\n",
" <td>7.0</td>\n",
" <td>NaN</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3</td>\n",
" <td>Chelsea</td>\n",
" <td>27</td>\n",
" <td>1038</td>\n",
" <td>558</td>\n",
" <td>257</td>\n",
" <td>223</td>\n",
" <td>1770</td>\n",
" <td>1002</td>\n",
" <td>768</td>\n",
" <td>1931</td>\n",
" <td>5.0</td>\n",
" <td>4.0</td>\n",
" <td>5.0</td>\n",
" <td>2.0</td>\n",
" <td>NaN</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>4</td>\n",
" <td>Liverpool</td>\n",
" <td>27</td>\n",
" <td>1038</td>\n",
" <td>529</td>\n",
" <td>262</td>\n",
" <td>247</td>\n",
" <td>1774</td>\n",
" <td>1046</td>\n",
" <td>728</td>\n",
" <td>1849</td>\n",
" <td>NaN</td>\n",
" <td>4.0</td>\n",
" <td>5.0</td>\n",
" <td>7.0</td>\n",
" <td>NaN</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>5</td>\n",
" <td>Tottenham Hotspur</td>\n",
" <td>27</td>\n",
" <td>1038</td>\n",
" <td>446</td>\n",
" <td>257</td>\n",
" <td>335</td>\n",
" <td>1547</td>\n",
" <td>1306</td>\n",
" <td>241</td>\n",
" <td>1595</td>\n",
" <td>NaN</td>\n",
" <td>1.0</td>\n",
" <td>2.0</td>\n",
" <td>3.0</td>\n",
" <td>NaN</td>\n",
" <td>2</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Pos. Club Seasons Pld Win Draw Loss GF GA GD \\\n",
"0 1 Manchester United 27 1038 648 224 166 1989 929 1060 \n",
"1 2 Arsenal 27 1038 565 260 213 1845 1013 832 \n",
"2 3 Chelsea 27 1038 558 257 223 1770 1002 768 \n",
"3 4 Liverpool 27 1038 529 262 247 1774 1046 728 \n",
"4 5 Tottenham Hotspur 27 1038 446 257 335 1547 1306 241 \n",
"\n",
" Pts 1st 2nd 3rd 4th Relegated BestPos. \n",
"0 2168 13.0 6.0 3.0 1.0 NaN 1 \n",
"1 1955 3.0 6.0 5.0 7.0 NaN 1 \n",
"2 1931 5.0 4.0 5.0 2.0 NaN 1 \n",
"3 1849 NaN 4.0 5.0 7.0 NaN 2 \n",
"4 1595 NaN 1.0 2.0 3.0 NaN 2 "
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Best 5 teams \n",
"df[df['Pos.'] <= 5]"
]
},
{
"cell_type": "code",
"execution_count": 18,
"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>Pos.</th>\n",
" <th>Club</th>\n",
" <th>Seasons</th>\n",
" <th>Pld</th>\n",
" <th>Win</th>\n",
" <th>Draw</th>\n",
" <th>Loss</th>\n",
" <th>GF</th>\n",
" <th>GA</th>\n",
" <th>GD</th>\n",
" <th>Pts</th>\n",
" <th>1st</th>\n",
" <th>2nd</th>\n",
" <th>3rd</th>\n",
" <th>4th</th>\n",
" <th>Relegated</th>\n",
" <th>BestPos.</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>5</td>\n",
" <td>Tottenham Hotspur</td>\n",
" <td>27</td>\n",
" <td>1038</td>\n",
" <td>446</td>\n",
" <td>257</td>\n",
" <td>335</td>\n",
" <td>1547</td>\n",
" <td>1306</td>\n",
" <td>241</td>\n",
" <td>1595</td>\n",
" <td>NaN</td>\n",
" <td>1.0</td>\n",
" <td>2.0</td>\n",
" <td>3.0</td>\n",
" <td>NaN</td>\n",
" <td>2</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Pos. Club Seasons Pld Win Draw Loss GF GA GD \\\n",
"4 5 Tottenham Hotspur 27 1038 446 257 335 1547 1306 241 \n",
"\n",
" Pts 1st 2nd 3rd 4th Relegated BestPos. \n",
"4 1595 NaN 1.0 2.0 3.0 NaN 2 "
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Only number 5\n",
"df[df['Pos.'] == 5]"
]
},
{
"cell_type": "code",
"execution_count": 19,
"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>Pos.</th>\n",
" <th>Club</th>\n",
" <th>Seasons</th>\n",
" <th>Pld</th>\n",
" <th>Win</th>\n",
" <th>Draw</th>\n",
" <th>Loss</th>\n",
" <th>GF</th>\n",
" <th>GA</th>\n",
" <th>GD</th>\n",
" <th>Pts</th>\n",
" <th>1st</th>\n",
" <th>2nd</th>\n",
" <th>3rd</th>\n",
" <th>4th</th>\n",
" <th>Relegated</th>\n",
" <th>BestPos.</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>Manchester United</td>\n",
" <td>27</td>\n",
" <td>1038</td>\n",
" <td>648</td>\n",
" <td>224</td>\n",
" <td>166</td>\n",
" <td>1989</td>\n",
" <td>929</td>\n",
" <td>1060</td>\n",
" <td>2168</td>\n",
" <td>13.0</td>\n",
" <td>6.0</td>\n",
" <td>3.0</td>\n",
" <td>1.0</td>\n",
" <td>NaN</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" <td>Arsenal</td>\n",
" <td>27</td>\n",
" <td>1038</td>\n",
" <td>565</td>\n",
" <td>260</td>\n",
" <td>213</td>\n",
" <td>1845</td>\n",
" <td>1013</td>\n",
" <td>832</td>\n",
" <td>1955</td>\n",
" <td>3.0</td>\n",
" <td>6.0</td>\n",
" <td>5.0</td>\n",
" <td>7.0</td>\n",
" <td>NaN</td>\n",
" <td>1</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Pos. Club Seasons Pld Win Draw Loss GF GA GD \\\n",
"0 1 Manchester United 27 1038 648 224 166 1989 929 1060 \n",
"1 2 Arsenal 27 1038 565 260 213 1845 1013 832 \n",
"\n",
" Pts 1st 2nd 3rd 4th Relegated BestPos. \n",
"0 2168 13.0 6.0 3.0 1.0 NaN 1 \n",
"1 1955 3.0 6.0 5.0 7.0 NaN 1 "
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# More than 3 1st and aslo more than 560 Win\n",
"df[(df['1st'] >= 3) & (df['Win'] > 560)]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment