diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb
index ee9444d..42cc1a8 100644
--- a/Python-ifed.ipynb
+++ b/Python-ifed.ipynb
@@ -62,15 +62,15 @@
"### Describe what each of the following means\n",
"\n",
"#### Production\n",
- "(Insert answer here)\n",
+ "It is an environment for the final output of the work. It states that the software is ready to be used by individuals. \n",
"#### Clean \n",
- "(Insert answer here)\n",
+ "A code is said to be clean if it follows any coding standard. The main features of a clean code being easy to read, easy to debug, OOP concepts have been implemented, etc.\n",
"#### Modular\n",
- "(Insert answer here)\n",
+ "A modular program has different modules that interact with each other for the working.\n",
"#### Module\n",
- "(Insert answer here)\n",
+ "Each module of a modular program will be handling one aspect of the desired functionality.\n",
"#### Refactoring code\n",
- "(Insert answer here)"
+ "Refactoring code is the process of changing the code without altering the functionality. "
]
},
{
@@ -93,9 +93,214 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Season | \n",
+ " city | \n",
+ " date | \n",
+ " team 1 | \n",
+ " team 2 | \n",
+ " toss winner | \n",
+ " toss decision | \n",
+ " result | \n",
+ " dl applied | \n",
+ " winner | \n",
+ " win by runs | \n",
+ " win by wickets | \n",
+ " player of match | \n",
+ " venue | \n",
+ " umpire 1 | \n",
+ " umpire 2 | \n",
+ "
\n",
+ " \n",
+ " | id | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 1 | \n",
+ " IPL-2017 | \n",
+ " Hyderabad | \n",
+ " 05-04-2017 | \n",
+ " Sunrisers Hyderabad | \n",
+ " Royal Challengers Bangalore | \n",
+ " Royal Challengers Bangalore | \n",
+ " field | \n",
+ " normal | \n",
+ " 0 | \n",
+ " Sunrisers Hyderabad | \n",
+ " 35 | \n",
+ " 0 | \n",
+ " Yuvraj Singh | \n",
+ " Rajiv Gandhi International Stadium, Uppal | \n",
+ " AY Dandekar | \n",
+ " NJ Llong | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " IPL-2017 | \n",
+ " Pune | \n",
+ " 06-04-2017 | \n",
+ " Mumbai Indians | \n",
+ " Rising Pune Supergiant | \n",
+ " Rising Pune Supergiant | \n",
+ " field | \n",
+ " normal | \n",
+ " 0 | \n",
+ " Rising Pune Supergiant | \n",
+ " 0 | \n",
+ " 7 | \n",
+ " SPD Smith | \n",
+ " Maharashtra Cricket Association Stadium | \n",
+ " A Nand Kishore | \n",
+ " S Ravi | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " IPL-2017 | \n",
+ " Rajkot | \n",
+ " 07-04-2017 | \n",
+ " Gujarat Lions | \n",
+ " Kolkata Knight Riders | \n",
+ " Kolkata Knight Riders | \n",
+ " field | \n",
+ " normal | \n",
+ " 0 | \n",
+ " Kolkata Knight Riders | \n",
+ " 0 | \n",
+ " 10 | \n",
+ " CA Lynn | \n",
+ " Saurashtra Cricket Association Stadium | \n",
+ " Nitin Menon | \n",
+ " CK Nandan | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " IPL-2017 | \n",
+ " Indore | \n",
+ " 08-04-2017 | \n",
+ " Rising Pune Supergiant | \n",
+ " Kings XI Punjab | \n",
+ " Kings XI Punjab | \n",
+ " field | \n",
+ " normal | \n",
+ " 0 | \n",
+ " Kings XI Punjab | \n",
+ " 0 | \n",
+ " 6 | \n",
+ " GJ Maxwell | \n",
+ " Holkar Cricket Stadium | \n",
+ " AK Chaudhary | \n",
+ " C Shamshuddin | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " IPL-2017 | \n",
+ " Bangalore | \n",
+ " 08-04-2017 | \n",
+ " Royal Challengers Bangalore | \n",
+ " Delhi Daredevils | \n",
+ " Royal Challengers Bangalore | \n",
+ " bat | \n",
+ " normal | \n",
+ " 0 | \n",
+ " Royal Challengers Bangalore | \n",
+ " 15 | \n",
+ " 0 | \n",
+ " KM Jadhav | \n",
+ " M Chinnaswamy Stadium | \n",
+ " NaN | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Season city date team 1 \\\n",
+ "id \n",
+ "1 IPL-2017 Hyderabad 05-04-2017 Sunrisers Hyderabad \n",
+ "2 IPL-2017 Pune 06-04-2017 Mumbai Indians \n",
+ "3 IPL-2017 Rajkot 07-04-2017 Gujarat Lions \n",
+ "4 IPL-2017 Indore 08-04-2017 Rising Pune Supergiant \n",
+ "5 IPL-2017 Bangalore 08-04-2017 Royal Challengers Bangalore \n",
+ "\n",
+ " team 2 toss winner toss decision \\\n",
+ "id \n",
+ "1 Royal Challengers Bangalore Royal Challengers Bangalore field \n",
+ "2 Rising Pune Supergiant Rising Pune Supergiant field \n",
+ "3 Kolkata Knight Riders Kolkata Knight Riders field \n",
+ "4 Kings XI Punjab Kings XI Punjab field \n",
+ "5 Delhi Daredevils Royal Challengers Bangalore bat \n",
+ "\n",
+ " result dl applied winner win by runs \\\n",
+ "id \n",
+ "1 normal 0 Sunrisers Hyderabad 35 \n",
+ "2 normal 0 Rising Pune Supergiant 0 \n",
+ "3 normal 0 Kolkata Knight Riders 0 \n",
+ "4 normal 0 Kings XI Punjab 0 \n",
+ "5 normal 0 Royal Challengers Bangalore 15 \n",
+ "\n",
+ " win by wickets player of match venue \\\n",
+ "id \n",
+ "1 0 Yuvraj Singh Rajiv Gandhi International Stadium, Uppal \n",
+ "2 7 SPD Smith Maharashtra Cricket Association Stadium \n",
+ "3 10 CA Lynn Saurashtra Cricket Association Stadium \n",
+ "4 6 GJ Maxwell Holkar Cricket Stadium \n",
+ "5 0 KM Jadhav M Chinnaswamy Stadium \n",
+ "\n",
+ " umpire 1 umpire 2 \n",
+ "id \n",
+ "1 AY Dandekar NJ Llong \n",
+ "2 A Nand Kishore S Ravi \n",
+ "3 Nitin Menon CK Nandan \n",
+ "4 AK Chaudhary C Shamshuddin \n",
+ "5 NaN NaN "
+ ]
+ },
+ "execution_count": 1,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"import pandas as pd\n",
"df = pd.read_csv('matches.csv', sep=',')\n",
@@ -113,9 +318,214 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Season | \n",
+ " city | \n",
+ " date | \n",
+ " team_1 | \n",
+ " team_2 | \n",
+ " toss_winner | \n",
+ " toss decision | \n",
+ " result | \n",
+ " dl_applied | \n",
+ " winner | \n",
+ " win_by_runs | \n",
+ " win_by_wickets | \n",
+ " player_of_match | \n",
+ " venue | \n",
+ " umpire_1 | \n",
+ " umpire_2 | \n",
+ "
\n",
+ " \n",
+ " | id | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 1 | \n",
+ " IPL-2017 | \n",
+ " Hyderabad | \n",
+ " 05-04-2017 | \n",
+ " Sunrisers Hyderabad | \n",
+ " Royal Challengers Bangalore | \n",
+ " Royal Challengers Bangalore | \n",
+ " field | \n",
+ " normal | \n",
+ " 0 | \n",
+ " Sunrisers Hyderabad | \n",
+ " 35 | \n",
+ " 0 | \n",
+ " Yuvraj Singh | \n",
+ " Rajiv Gandhi International Stadium, Uppal | \n",
+ " AY Dandekar | \n",
+ " NJ Llong | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " IPL-2017 | \n",
+ " Pune | \n",
+ " 06-04-2017 | \n",
+ " Mumbai Indians | \n",
+ " Rising Pune Supergiant | \n",
+ " Rising Pune Supergiant | \n",
+ " field | \n",
+ " normal | \n",
+ " 0 | \n",
+ " Rising Pune Supergiant | \n",
+ " 0 | \n",
+ " 7 | \n",
+ " SPD Smith | \n",
+ " Maharashtra Cricket Association Stadium | \n",
+ " A Nand Kishore | \n",
+ " S Ravi | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " IPL-2017 | \n",
+ " Rajkot | \n",
+ " 07-04-2017 | \n",
+ " Gujarat Lions | \n",
+ " Kolkata Knight Riders | \n",
+ " Kolkata Knight Riders | \n",
+ " field | \n",
+ " normal | \n",
+ " 0 | \n",
+ " Kolkata Knight Riders | \n",
+ " 0 | \n",
+ " 10 | \n",
+ " CA Lynn | \n",
+ " Saurashtra Cricket Association Stadium | \n",
+ " Nitin Menon | \n",
+ " CK Nandan | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " IPL-2017 | \n",
+ " Indore | \n",
+ " 08-04-2017 | \n",
+ " Rising Pune Supergiant | \n",
+ " Kings XI Punjab | \n",
+ " Kings XI Punjab | \n",
+ " field | \n",
+ " normal | \n",
+ " 0 | \n",
+ " Kings XI Punjab | \n",
+ " 0 | \n",
+ " 6 | \n",
+ " GJ Maxwell | \n",
+ " Holkar Cricket Stadium | \n",
+ " AK Chaudhary | \n",
+ " C Shamshuddin | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " IPL-2017 | \n",
+ " Bangalore | \n",
+ " 08-04-2017 | \n",
+ " Royal Challengers Bangalore | \n",
+ " Delhi Daredevils | \n",
+ " Royal Challengers Bangalore | \n",
+ " bat | \n",
+ " normal | \n",
+ " 0 | \n",
+ " Royal Challengers Bangalore | \n",
+ " 15 | \n",
+ " 0 | \n",
+ " KM Jadhav | \n",
+ " M Chinnaswamy Stadium | \n",
+ " NaN | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Season city date team_1 \\\n",
+ "id \n",
+ "1 IPL-2017 Hyderabad 05-04-2017 Sunrisers Hyderabad \n",
+ "2 IPL-2017 Pune 06-04-2017 Mumbai Indians \n",
+ "3 IPL-2017 Rajkot 07-04-2017 Gujarat Lions \n",
+ "4 IPL-2017 Indore 08-04-2017 Rising Pune Supergiant \n",
+ "5 IPL-2017 Bangalore 08-04-2017 Royal Challengers Bangalore \n",
+ "\n",
+ " team_2 toss_winner toss decision \\\n",
+ "id \n",
+ "1 Royal Challengers Bangalore Royal Challengers Bangalore field \n",
+ "2 Rising Pune Supergiant Rising Pune Supergiant field \n",
+ "3 Kolkata Knight Riders Kolkata Knight Riders field \n",
+ "4 Kings XI Punjab Kings XI Punjab field \n",
+ "5 Delhi Daredevils Royal Challengers Bangalore bat \n",
+ "\n",
+ " result dl_applied winner win_by_runs \\\n",
+ "id \n",
+ "1 normal 0 Sunrisers Hyderabad 35 \n",
+ "2 normal 0 Rising Pune Supergiant 0 \n",
+ "3 normal 0 Kolkata Knight Riders 0 \n",
+ "4 normal 0 Kings XI Punjab 0 \n",
+ "5 normal 0 Royal Challengers Bangalore 15 \n",
+ "\n",
+ " win_by_wickets player_of_match venue \\\n",
+ "id \n",
+ "1 0 Yuvraj Singh Rajiv Gandhi International Stadium, Uppal \n",
+ "2 7 SPD Smith Maharashtra Cricket Association Stadium \n",
+ "3 10 CA Lynn Saurashtra Cricket Association Stadium \n",
+ "4 6 GJ Maxwell Holkar Cricket Stadium \n",
+ "5 0 KM Jadhav M Chinnaswamy Stadium \n",
+ "\n",
+ " umpire_1 umpire_2 \n",
+ "id \n",
+ "1 AY Dandekar NJ Llong \n",
+ "2 A Nand Kishore S Ravi \n",
+ "3 Nitin Menon CK Nandan \n",
+ "4 AK Chaudhary C Shamshuddin \n",
+ "5 NaN NaN "
+ ]
+ },
+ "execution_count": 2,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"new_df = df.rename(columns={'team 1': 'team_1',\n",
" 'team 2': 'team_2',\n",
@@ -139,9 +549,214 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Season | \n",
+ " city | \n",
+ " date | \n",
+ " team_1 | \n",
+ " team 2 | \n",
+ " toss_winner | \n",
+ " toss_decision | \n",
+ " result | \n",
+ " dl_applied | \n",
+ " winner | \n",
+ " win_by_runs | \n",
+ " win by wickets | \n",
+ " player of match | \n",
+ " venue | \n",
+ " umpire 1 | \n",
+ " umpire 2 | \n",
+ "
\n",
+ " \n",
+ " | id | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 1 | \n",
+ " IPL-2017 | \n",
+ " Hyderabad | \n",
+ " 05-04-2017 | \n",
+ " Sunrisers Hyderabad | \n",
+ " Royal Challengers Bangalore | \n",
+ " Royal Challengers Bangalore | \n",
+ " field | \n",
+ " normal | \n",
+ " 0 | \n",
+ " Sunrisers Hyderabad | \n",
+ " 35 | \n",
+ " 0 | \n",
+ " Yuvraj Singh | \n",
+ " Rajiv Gandhi International Stadium, Uppal | \n",
+ " AY Dandekar | \n",
+ " NJ Llong | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " IPL-2017 | \n",
+ " Pune | \n",
+ " 06-04-2017 | \n",
+ " Mumbai Indians | \n",
+ " Rising Pune Supergiant | \n",
+ " Rising Pune Supergiant | \n",
+ " field | \n",
+ " normal | \n",
+ " 0 | \n",
+ " Rising Pune Supergiant | \n",
+ " 0 | \n",
+ " 7 | \n",
+ " SPD Smith | \n",
+ " Maharashtra Cricket Association Stadium | \n",
+ " A Nand Kishore | \n",
+ " S Ravi | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " IPL-2017 | \n",
+ " Rajkot | \n",
+ " 07-04-2017 | \n",
+ " Gujarat Lions | \n",
+ " Kolkata Knight Riders | \n",
+ " Kolkata Knight Riders | \n",
+ " field | \n",
+ " normal | \n",
+ " 0 | \n",
+ " Kolkata Knight Riders | \n",
+ " 0 | \n",
+ " 10 | \n",
+ " CA Lynn | \n",
+ " Saurashtra Cricket Association Stadium | \n",
+ " Nitin Menon | \n",
+ " CK Nandan | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " IPL-2017 | \n",
+ " Indore | \n",
+ " 08-04-2017 | \n",
+ " Rising Pune Supergiant | \n",
+ " Kings XI Punjab | \n",
+ " Kings XI Punjab | \n",
+ " field | \n",
+ " normal | \n",
+ " 0 | \n",
+ " Kings XI Punjab | \n",
+ " 0 | \n",
+ " 6 | \n",
+ " GJ Maxwell | \n",
+ " Holkar Cricket Stadium | \n",
+ " AK Chaudhary | \n",
+ " C Shamshuddin | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " IPL-2017 | \n",
+ " Bangalore | \n",
+ " 08-04-2017 | \n",
+ " Royal Challengers Bangalore | \n",
+ " Delhi Daredevils | \n",
+ " Royal Challengers Bangalore | \n",
+ " bat | \n",
+ " normal | \n",
+ " 0 | \n",
+ " Royal Challengers Bangalore | \n",
+ " 15 | \n",
+ " 0 | \n",
+ " KM Jadhav | \n",
+ " M Chinnaswamy Stadium | \n",
+ " NaN | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Season city date team_1 \\\n",
+ "id \n",
+ "1 IPL-2017 Hyderabad 05-04-2017 Sunrisers Hyderabad \n",
+ "2 IPL-2017 Pune 06-04-2017 Mumbai Indians \n",
+ "3 IPL-2017 Rajkot 07-04-2017 Gujarat Lions \n",
+ "4 IPL-2017 Indore 08-04-2017 Rising Pune Supergiant \n",
+ "5 IPL-2017 Bangalore 08-04-2017 Royal Challengers Bangalore \n",
+ "\n",
+ " team 2 toss_winner toss_decision \\\n",
+ "id \n",
+ "1 Royal Challengers Bangalore Royal Challengers Bangalore field \n",
+ "2 Rising Pune Supergiant Rising Pune Supergiant field \n",
+ "3 Kolkata Knight Riders Kolkata Knight Riders field \n",
+ "4 Kings XI Punjab Kings XI Punjab field \n",
+ "5 Delhi Daredevils Royal Challengers Bangalore bat \n",
+ "\n",
+ " result dl_applied winner win_by_runs \\\n",
+ "id \n",
+ "1 normal 0 Sunrisers Hyderabad 35 \n",
+ "2 normal 0 Rising Pune Supergiant 0 \n",
+ "3 normal 0 Kolkata Knight Riders 0 \n",
+ "4 normal 0 Kings XI Punjab 0 \n",
+ "5 normal 0 Royal Challengers Bangalore 15 \n",
+ "\n",
+ " win by wickets player of match venue \\\n",
+ "id \n",
+ "1 0 Yuvraj Singh Rajiv Gandhi International Stadium, Uppal \n",
+ "2 7 SPD Smith Maharashtra Cricket Association Stadium \n",
+ "3 10 CA Lynn Saurashtra Cricket Association Stadium \n",
+ "4 6 GJ Maxwell Holkar Cricket Stadium \n",
+ "5 0 KM Jadhav M Chinnaswamy Stadium \n",
+ "\n",
+ " umpire 1 umpire 2 \n",
+ "id \n",
+ "1 AY Dandekar NJ Llong \n",
+ "2 A Nand Kishore S Ravi \n",
+ "3 Nitin Menon CK Nandan \n",
+ "4 AK Chaudhary C Shamshuddin \n",
+ "5 NaN NaN "
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"labels = list(df.columns)\n",
"labels[0] = labels[0].replace(' ', '_')\n",
@@ -167,11 +782,217 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 4,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Season | \n",
+ " city | \n",
+ " date | \n",
+ " team_1 | \n",
+ " team_2 | \n",
+ " toss_winner | \n",
+ " toss_decision | \n",
+ " result | \n",
+ " dl_applied | \n",
+ " winner | \n",
+ " win_by_runs | \n",
+ " win_by_wickets | \n",
+ " player_of_match | \n",
+ " venue | \n",
+ " umpire_1 | \n",
+ " umpire_2 | \n",
+ "
\n",
+ " \n",
+ " | id | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 1 | \n",
+ " IPL-2017 | \n",
+ " Hyderabad | \n",
+ " 05-04-2017 | \n",
+ " Sunrisers Hyderabad | \n",
+ " Royal Challengers Bangalore | \n",
+ " Royal Challengers Bangalore | \n",
+ " field | \n",
+ " normal | \n",
+ " 0 | \n",
+ " Sunrisers Hyderabad | \n",
+ " 35 | \n",
+ " 0 | \n",
+ " Yuvraj Singh | \n",
+ " Rajiv Gandhi International Stadium, Uppal | \n",
+ " AY Dandekar | \n",
+ " NJ Llong | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " IPL-2017 | \n",
+ " Pune | \n",
+ " 06-04-2017 | \n",
+ " Mumbai Indians | \n",
+ " Rising Pune Supergiant | \n",
+ " Rising Pune Supergiant | \n",
+ " field | \n",
+ " normal | \n",
+ " 0 | \n",
+ " Rising Pune Supergiant | \n",
+ " 0 | \n",
+ " 7 | \n",
+ " SPD Smith | \n",
+ " Maharashtra Cricket Association Stadium | \n",
+ " A Nand Kishore | \n",
+ " S Ravi | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " IPL-2017 | \n",
+ " Rajkot | \n",
+ " 07-04-2017 | \n",
+ " Gujarat Lions | \n",
+ " Kolkata Knight Riders | \n",
+ " Kolkata Knight Riders | \n",
+ " field | \n",
+ " normal | \n",
+ " 0 | \n",
+ " Kolkata Knight Riders | \n",
+ " 0 | \n",
+ " 10 | \n",
+ " CA Lynn | \n",
+ " Saurashtra Cricket Association Stadium | \n",
+ " Nitin Menon | \n",
+ " CK Nandan | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " IPL-2017 | \n",
+ " Indore | \n",
+ " 08-04-2017 | \n",
+ " Rising Pune Supergiant | \n",
+ " Kings XI Punjab | \n",
+ " Kings XI Punjab | \n",
+ " field | \n",
+ " normal | \n",
+ " 0 | \n",
+ " Kings XI Punjab | \n",
+ " 0 | \n",
+ " 6 | \n",
+ " GJ Maxwell | \n",
+ " Holkar Cricket Stadium | \n",
+ " AK Chaudhary | \n",
+ " C Shamshuddin | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " IPL-2017 | \n",
+ " Bangalore | \n",
+ " 08-04-2017 | \n",
+ " Royal Challengers Bangalore | \n",
+ " Delhi Daredevils | \n",
+ " Royal Challengers Bangalore | \n",
+ " bat | \n",
+ " normal | \n",
+ " 0 | \n",
+ " Royal Challengers Bangalore | \n",
+ " 15 | \n",
+ " 0 | \n",
+ " KM Jadhav | \n",
+ " M Chinnaswamy Stadium | \n",
+ " NaN | \n",
+ " NaN | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Season city date team_1 \\\n",
+ "id \n",
+ "1 IPL-2017 Hyderabad 05-04-2017 Sunrisers Hyderabad \n",
+ "2 IPL-2017 Pune 06-04-2017 Mumbai Indians \n",
+ "3 IPL-2017 Rajkot 07-04-2017 Gujarat Lions \n",
+ "4 IPL-2017 Indore 08-04-2017 Rising Pune Supergiant \n",
+ "5 IPL-2017 Bangalore 08-04-2017 Royal Challengers Bangalore \n",
+ "\n",
+ " team_2 toss_winner toss_decision \\\n",
+ "id \n",
+ "1 Royal Challengers Bangalore Royal Challengers Bangalore field \n",
+ "2 Rising Pune Supergiant Rising Pune Supergiant field \n",
+ "3 Kolkata Knight Riders Kolkata Knight Riders field \n",
+ "4 Kings XI Punjab Kings XI Punjab field \n",
+ "5 Delhi Daredevils Royal Challengers Bangalore bat \n",
+ "\n",
+ " result dl_applied winner win_by_runs \\\n",
+ "id \n",
+ "1 normal 0 Sunrisers Hyderabad 35 \n",
+ "2 normal 0 Rising Pune Supergiant 0 \n",
+ "3 normal 0 Kolkata Knight Riders 0 \n",
+ "4 normal 0 Kings XI Punjab 0 \n",
+ "5 normal 0 Royal Challengers Bangalore 15 \n",
+ "\n",
+ " win_by_wickets player_of_match venue \\\n",
+ "id \n",
+ "1 0 Yuvraj Singh Rajiv Gandhi International Stadium, Uppal \n",
+ "2 7 SPD Smith Maharashtra Cricket Association Stadium \n",
+ "3 10 CA Lynn Saurashtra Cricket Association Stadium \n",
+ "4 6 GJ Maxwell Holkar Cricket Stadium \n",
+ "5 0 KM Jadhav M Chinnaswamy Stadium \n",
+ "\n",
+ " umpire_1 umpire_2 \n",
+ "id \n",
+ "1 AY Dandekar NJ Llong \n",
+ "2 A Nand Kishore S Ravi \n",
+ "3 Nitin Menon CK Nandan \n",
+ "4 AK Chaudhary C Shamshuddin \n",
+ "5 NaN NaN "
+ ]
+ },
+ "execution_count": 4,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Insert your solution here"
+ "df.columns = list(map(lambda l: l.replace(' ', '_'), list(df.columns)))\n",
+ "df.head()"
]
},
{
@@ -208,7 +1029,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
@@ -219,11 +1040,11 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
- "with open('subset_elemets.txt') as f:\n",
+ "with open('subset_elements.txt') as f:\n",
" subset_elements = f.read().split('\\n')\n",
" \n",
"with open('all_elements.txt') as f:\n",
@@ -233,9 +1054,18 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 7,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "96\n",
+ "Duration: 16.00716996192932 seconds\n"
+ ]
+ }
+ ],
"source": [
"start = time.time()\n",
"verified_elements = []\n",
@@ -257,11 +1087,21 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 8,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "96\n",
+ "Duration: 0.05529594421386719 seconds\n"
+ ]
+ }
+ ],
"source": [
- "# Insert answer here\n",
+ "start = time.time()\n",
+ "verified_elements = np.intersect1d(np.array(subset_elements), np.array(all_elements))\n",
"\n",
"print(len(verified_elements))\n",
"print('Duration: {} seconds'.format(time.time() - start))"
@@ -276,11 +1116,21 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 9,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "96\n",
+ "Duration: 0.013680219650268555 seconds\n"
+ ]
+ }
+ ],
"source": [
- "# Insert answer here\n",
+ "start = time.time()\n",
+ "verified_elements = set(subset_elements) & set(all_elements)\n",
"\n",
"print(len(verified_elements))\n",
"print('Duration: {} seconds'.format(time.time() - start))"
@@ -330,9 +1180,24 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 10,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\u001b[1m============================= test session starts ==============================\u001b[0m\n",
+ "platform darwin -- Python 3.8.3, pytest-5.4.3, py-1.9.0, pluggy-0.13.1\n",
+ "rootdir: /Users/advaith/Sites/Python-ifed-challenge\n",
+ "collected 4 items \u001b[0m\n",
+ "\n",
+ "test_nearest_square.py \u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m [100%]\u001b[0m\n",
+ "\n",
+ "\u001b[32m============================== \u001b[32m\u001b[1m4 passed\u001b[0m\u001b[32m in 0.02s\u001b[0m\u001b[32m ===============================\u001b[0m\n"
+ ]
+ }
+ ],
"source": [
"! pytest test_nearest_square.py"
]
@@ -386,11 +1251,46 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 11,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Pokemon's type: ['normal', 'flying']\n"
+ ]
+ }
+ ],
"source": [
- "# Insert your code here"
+ "import requests\n",
+ "\n",
+ "\n",
+ "def parseJSON(url):\n",
+ " \"\"\"\n",
+ " Function get JSON response from provided url\n",
+ " :param url:\n",
+ " :return JSON:\n",
+ " \"\"\"\n",
+ " req = requests.get(url)\n",
+ " req.raise_for_status()\n",
+ " return req.json()\n",
+ "\n",
+ "\n",
+ "def pokeType(pokemon):\n",
+ " \"\"\"\n",
+ " Function to display a pokemon's type\n",
+ " :param pokemon:\n",
+ " :return types:\n",
+ " \"\"\"\n",
+ " res = parseJSON(f'https://pokeapi.co/api/v2/pokemon/{pokemon}')\n",
+ "\n",
+ " types = list(map(lambda t: t['type']['name'], res['types']))\n",
+ " print(f'Pokemon\\'s type: {str(types)}')\n",
+ " return types\n",
+ "\n",
+ "\n",
+ "types = pokeType('pidgeot')"
]
},
{
@@ -404,11 +1304,44 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 12,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Type normal:\n",
+ "Takes double damage from: ['fighting']\n",
+ "Takes half damage from: []\n",
+ "Type flying:\n",
+ "Takes double damage from: ['rock', 'electric', 'ice']\n",
+ "Takes half damage from: ['fighting', 'bug', 'grass']\n"
+ ]
+ }
+ ],
"source": [
- "# Insert your code here"
+ "def damageFrom(types):\n",
+ " \"\"\"\n",
+ " Function to display damage taken by a pokemon type from different types\n",
+ " :param url:\n",
+ " :return double_damage_types:\n",
+ " \"\"\"\n",
+ " double_damage_types = []\n",
+ " for poke_type in types:\n",
+ " res = parseJSON(f'https://pokeapi.co/api/v2/type/{poke_type}')\n",
+ " damages = res['damage_relations']\n",
+ "\n",
+ " print(f'Type {poke_type}:')\n",
+ " dd = list(map(lambda d: d['name'], damages['double_damage_from']))\n",
+ " print('Takes double damage from: ' + str(dd))\n",
+ " double_damage_types += dd\n",
+ " print('Takes half damage from: ' + str(list(map(lambda d: d['name'], damages['half_damage_from']))))\n",
+ "\n",
+ " return double_damage_types\n",
+ "\n",
+ "\n",
+ "double_damage_types = damageFrom(types)"
]
},
{
@@ -420,11 +1353,42 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 13,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Type fighting:\n",
+ "['mankey', 'primeape', 'poliwrath', 'machop', 'machoke']\n",
+ "Type rock:\n",
+ "['geodude', 'graveler', 'golem', 'onix', 'rhyhorn']\n",
+ "Type electric:\n",
+ "['pikachu', 'raichu', 'magnemite', 'magneton', 'voltorb']\n",
+ "Type ice:\n",
+ "['dewgong', 'cloyster', 'jynx', 'lapras', 'articuno']\n"
+ ]
+ }
+ ],
"source": [
- "# Insert your code here"
+ "def doubleDamageTypesPokemon(double_damage_types):\n",
+ " \"\"\"\n",
+ " Function to display 5 pokemons given a type\n",
+ " :param double_damage_types:\n",
+ " :return:\n",
+ " \"\"\"\n",
+ " for poke_type in double_damage_types:\n",
+ " res = parseJSON(f'https://pokeapi.co/api/v2/type/{poke_type}')\n",
+ " pokemons = res['pokemon']\n",
+ "\n",
+ " print(f'Type {poke_type}:')\n",
+ " names = []\n",
+ " for i in range(5):\n",
+ " names.append(pokemons[i]['pokemon']['name'])\n",
+ " print(names)\n",
+ " \n",
+ "doubleDamageTypesPokemon(double_damage_types)"
]
},
{
@@ -438,7 +1402,7 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 14,
"metadata": {},
"outputs": [
{
@@ -446,13 +1410,13 @@
"output_type": "stream",
"text": [
"\u001b[1m============================= test session starts ==============================\u001b[0m\n",
- "platform darwin -- Python 3.8.5, pytest-6.2.1, py-1.10.0, pluggy-0.13.1\n",
- "rootdir: /Users/abhijitramesh/development/Python-ifed\n",
- "collected 4 items \u001b[0m\n",
+ "platform darwin -- Python 3.8.3, pytest-5.4.3, py-1.9.0, pluggy-0.13.1\n",
+ "rootdir: /Users/advaith/Sites/Python-ifed-challenge\n",
+ "collected 4 items \u001b[0m\u001b[1m\n",
"\n",
"test_abilities.py \u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m [100%]\u001b[0m\n",
"\n",
- "\u001b[32m============================== \u001b[32m\u001b[1m4 passed\u001b[0m\u001b[32m in 2.75s\u001b[0m\u001b[32m ===============================\u001b[0m\n"
+ "\u001b[32m============================== \u001b[32m\u001b[1m4 passed\u001b[0m\u001b[32m in 3.85s\u001b[0m\u001b[32m ===============================\u001b[0m\n"
]
}
],
@@ -515,9 +1479,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.9"
+ "version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
-}
\ No newline at end of file
+}
diff --git a/ability.py b/ability.py
new file mode 100644
index 0000000..9747eb2
--- /dev/null
+++ b/ability.py
@@ -0,0 +1,75 @@
+import requests
+
+
+def parseJSON(url):
+ """
+ Function get JSON response from provided url
+ :param url:
+ :return JSON:
+ """
+ req = requests.get(url)
+ req.raise_for_status()
+ return req.json()
+
+
+def damageFrom(types):
+ """
+ Function to display damage taken by a pokemon type from different types
+ :param url:
+ :return double_damage_types:
+ """
+ double_damage_types = []
+ for poke_type in types:
+ res = parseJSON(f'https://pokeapi.co/api/v2/type/{poke_type}')
+ damages = res['damage_relations']
+
+ print(f'Type {poke_type}:')
+ dd = list(map(lambda d: d['name'], damages['double_damage_from']))
+ print('Takes double damage from: ' + str(dd))
+ double_damage_types += dd
+ print('Takes half damage from: ' + str(list(map(lambda d: d['name'], damages['half_damage_from']))))
+
+ return double_damage_types
+
+
+def pokeType(pokemon):
+ """
+ Function to display a pokemon's type
+ :param pokemon:
+ :return:
+ """
+ res = parseJSON(f'https://pokeapi.co/api/v2/pokemon/{pokemon}')
+
+ types = list(map(lambda t: t['type']['name'], res['types']))
+ print(f'Pokemon\'s type: {str(types)}')
+ return types
+
+
+def doubleDamageTypesPokemon(double_damage_types):
+ """
+ Function to display 5 pokemons given a type
+ :param double_damage_types:
+ :return:
+ """
+ for poke_type in double_damage_types:
+ res = parseJSON(f'https://pokeapi.co/api/v2/type/{poke_type}')
+ pokemons = res['pokemon']
+
+ print(f'Type {poke_type}:')
+ names = []
+ for i in range(5):
+ names.append(pokemons[i]['pokemon']['name'])
+ print(names)
+
+
+def ability(pokemon):
+ res = parseJSON(f'https://pokeapi.co/api/v2/pokemon/{pokemon}')
+ abilities = res['abilities']
+
+ return list(map(lambda a: a['ability']['name'], abilities))
+
+# types = pokeType('pidgeot')
+# print()
+# double_damage_types = damageFrom(types)
+# print()
+# doubleDamageTypesPokemon(double_damage_types)
diff --git a/nearest_square.py b/nearest_square.py
new file mode 100644
index 0000000..91bc0eb
--- /dev/null
+++ b/nearest_square.py
@@ -0,0 +1,5 @@
+from math import sqrt, floor
+
+
+def nearest_square(num):
+ return (floor(sqrt(num)) ** 2) if num > 0 else 0
diff --git a/pokedex.py b/pokedex.py
new file mode 100644
index 0000000..7e085d2
--- /dev/null
+++ b/pokedex.py
@@ -0,0 +1,50 @@
+import os
+import sys
+import PySimpleGUI as sg
+from ability import damageFrom, pokeType, doubleDamageTypesPokemon, ability
+
+# Define the window's contents
+layout = [[sg.Text("Enter pokemon's name")],
+ [sg.Input(size=(60, None), key='-INPUT-')],
+ [sg.Text(size=(60, 1), key='-OUTPUT-')],
+ [sg.Button('Get Info'), sg.Button('Quit')]]
+
+# Create the window
+window = sg.Window('Pokedex', layout)
+window.read()
+
+# Display and interact with the Window using an Event Loop
+while True:
+ event, values = window.read()
+ # See if user wants to quit or window was closed
+ if event == sg.WINDOW_CLOSED or event == 'Quit':
+ break
+
+ # See if user pressed 'Get Info' button
+ if event == 'Get Info':
+ os.remove('temp_output.txt')
+ file = open('temp_output.txt', 'w')
+ sys.stdout = file
+ try:
+ types = pokeType(values['-INPUT-'])
+ except:
+ window['-OUTPUT-'].set_size(size=(None, 1))
+ window['-OUTPUT-'].update(values['-INPUT-'] + " is not a valid pokemon")
+ continue
+
+ print()
+ double_damage_types = damageFrom(types)
+ print()
+ doubleDamageTypesPokemon(double_damage_types)
+ print()
+ abilities = ability(values['-INPUT-'])
+ print(f'Abilities: {abilities}')
+ file.close()
+ sys.stdout = sys.__stdout__
+
+ content = open('temp_output.txt').readlines()
+ window['-OUTPUT-'].set_size(size=(None, len(content)))
+ window['-OUTPUT-'].update(''.join(content))
+
+# Finish up by removing from the screen
+window.close()
diff --git a/step_4.py b/step_4.py
new file mode 100644
index 0000000..ffa320c
--- /dev/null
+++ b/step_4.py
@@ -0,0 +1,63 @@
+import time
+import numpy as np
+
+
+def standard(all_elements, subset_elements):
+ """
+ Standard way to find the intersection of two sets
+ :param all_elements:
+ :param subset_elements:
+ :return:
+ """
+ start = time.time()
+ verified_elements = []
+ for element in subset_elements:
+ if element in all_elements:
+ verified_elements.append(element)
+
+ print(len(verified_elements))
+ print('Duration: {} seconds'.format(time.time() - start))
+
+
+def numpy(all_elements, subset_elements):
+ """
+ Intersection of two sets using built-in functions of numpy
+ :param all_elements:
+ :param subset_elements:
+ :return:
+ """
+ start = time.time()
+ verified_elements = np.intersect1d(np.array(subset_elements), np.array(all_elements))
+
+ print(len(verified_elements))
+ print('Duration: {} seconds'.format(time.time() - start))
+
+
+def usingsets(all_elements, subset_elements):
+ """
+ Intersection of two sets using built-in set data structure of Python
+ :param all_elements:
+ :param subset_elements:
+ :return:
+ """
+ start = time.time()
+ verified_elements = set(subset_elements) & set(all_elements)
+
+ print(len(verified_elements))
+ print('Duration: {} seconds'.format(time.time() - start))
+
+
+with open('subset_elements.txt') as f:
+ subset_elements = f.read().split('\n')
+
+with open('all_elements.txt') as f:
+ all_elements = f.read().split('\n')
+
+print(standard.__doc__)
+standard(all_elements, subset_elements)
+
+print(numpy.__doc__)
+numpy(all_elements, subset_elements)
+
+print(usingsets.__doc__)
+usingsets(all_elements, subset_elements)
diff --git a/subset_elemets.txt b/subset_elements.txt
similarity index 100%
rename from subset_elemets.txt
rename to subset_elements.txt