Permalink
Browse files

oneliner for ch09

  • Loading branch information...
dsmdavid committed Feb 2, 2019
1 parent d700979 commit 42a2f2979c83f15f131e59088a0f5792b41259a7
Showing with 726 additions and 0 deletions.
  1. +348 −0 .ipynb_checkpoints/WC_09-checkpoint.ipynb
  2. +30 −0 09_files/09_input.csv
  3. +348 −0 WC_09.ipynb
@@ -0,0 +1,348 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Weekly Challenge 08\n",
"\n",
"*Original URL* https://community.alteryx.com/t5/Weekly-Challenge/Challenge-9-Analytics-Ranking/td-p/36736 and [**My Alteryx Approach**](https://github.com/dsmdavid/Alteryx-Weekly-Challenge/tree/master/submitted/sub_Challenge%2309)\n",
"\n",
"## Brief\n",
"\n",
"### Analytics Ranking:\n",
"\n",
"The objective is to determine the top 5 ranking based on the count, however since there are multiple rows with same count (similar to a round of golf) multiple people can be in the same place (Rank) if they have the same score.\n",
"\n",
"We have listed this as a beginner challenge and I expect it will go very quickly for many of you. Let us know what you think, we are looking forward to hearing your feedback."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"## Approach I want to follow:\n",
"1. Read the data.\n",
"1. Find top 5 ranks.\n",
"1. Find Matching Players."
]
},
{
"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>First</th>\n",
" <th>count</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>BOB</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>BRADY</td>\n",
" <td>14</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>BURTON</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>CARLA</td>\n",
" <td>14</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>CHRIS</td>\n",
" <td>14</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" First count\n",
"0 BOB 3\n",
"1 BRADY 14\n",
"2 BURTON 4\n",
"3 CARLA 14\n",
"4 CHRIS 14"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Load the data\n",
"df = pd.read_csv(\"./09_files/09_input.csv\")#,dtype=int)\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"#Find top 5 ranks\n",
"top5 = sorted(df['count'].unique(),reverse=True)[0:5]"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"#Find Players with score in top 5:\n",
"players_with_top5_score = df[df['count'] >= min(top5)]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"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>First</th>\n",
" <th>count</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>JANET</td>\n",
" <td>17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>MARK</td>\n",
" <td>17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>PAUL</td>\n",
" <td>15</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>BRADY</td>\n",
" <td>14</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>CARLA</td>\n",
" <td>14</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>CHRIS</td>\n",
" <td>14</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>LINDA</td>\n",
" <td>14</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>DALE</td>\n",
" <td>13</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>LUANNE</td>\n",
" <td>13</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>GUY</td>\n",
" <td>11</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>LASKA</td>\n",
" <td>11</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>SHARON</td>\n",
" <td>11</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" First count\n",
"11 JANET 17\n",
"23 MARK 17\n",
"24 PAUL 15\n",
"1 BRADY 14\n",
"3 CARLA 14\n",
"4 CHRIS 14\n",
"16 LINDA 14\n",
"5 DALE 13\n",
"19 LUANNE 13\n",
"9 GUY 11\n",
"15 LASKA 11\n",
"27 SHARON 11"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"players_with_top5_score.sort_values(by='count', ascending=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Condensed approach:"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" First count\n",
"11 JANET 17\n",
"23 MARK 17\n",
"24 PAUL 15\n",
"1 BRADY 14\n",
"3 CARLA 14\n",
"4 CHRIS 14\n",
"16 LINDA 14\n",
"5 DALE 13\n",
"19 LUANNE 13\n",
"9 GUY 11\n",
"15 LASKA 11\n",
"27 SHARON 11\n"
]
},
{
"data": {
"text/plain": [
"0.006513833999633789"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import time\n",
"t1 = time.time()\n",
"import pandas as pd\n",
"\n",
"#Input data\n",
"df = pd.read_csv(\"./09_files/09_input.csv\")#,dtype=int)\n",
"#One liner\n",
"print(df[df['count'] >= min(sorted(df['count'].unique(),reverse=True)[0:5])].sort_values(by='count', ascending=False))\n",
"\n",
"t2 = time.time()\n",
"t2-t1"
]
},
{
"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.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
@@ -0,0 +1,30 @@
First,count
BOB,3
BRADY,14
BURTON,4
CARLA,14
CHRIS,14
DALE,13
DAVID,3
ED,4
ERIC,2
GUY,11
ISABEL,2
JANET,17
JENNIFER,6
JERI,8
JOHN,4
LASKA,11
LINDA,14
LISA,4
LOVELL,8
LUANNE,13
LUCILLE,1
MARCIA,4
MARIE,6
MARK,17
PAUL,15
ROBERT,7
ROBIN,4
SHARON,11
SUSAN,2
Oops, something went wrong.

0 comments on commit 42a2f29

Please sign in to comment.