From febc747b21ddefdcf10e6465fdca19d529e4199a Mon Sep 17 00:00:00 2001 From: advaith3600 Date: Sat, 9 Jan 2021 18:21:44 +0530 Subject: [PATCH 1/7] step 1 completed --- Python-ifed.ipynb | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index ee9444d..48dcc74 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. " ] }, { @@ -170,9 +170,7 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "# Insert your solution here" - ] + "source": [] }, { "cell_type": "markdown", @@ -515,9 +513,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 +} From 36ad72d7300567fe5c9e76aabbf67d031290d91d Mon Sep 17 00:00:00 2001 From: advaith3600 Date: Sat, 9 Jan 2021 18:39:31 +0530 Subject: [PATCH 2/7] step 2 complete --- Python-ifed.ipynb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index 48dcc74..56dc9ff 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -170,7 +170,10 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "df.columns = list(map(lambda l: l.replace(' ', '_'), list(df.columns)))\n", + "df.head()" + ] }, { "cell_type": "markdown", From 0e7a75edba9fc3eac8879af11405c943c10be64e Mon Sep 17 00:00:00 2001 From: advaith3600 Date: Sat, 9 Jan 2021 19:04:25 +0530 Subject: [PATCH 3/7] step 3 completed --- Python-ifed.ipynb | 910 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 872 insertions(+), 38 deletions(-) diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index 56dc9ff..061041a 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Seasoncitydateteam 1team 2toss winnertoss decisionresultdl appliedwinnerwin by runswin by wicketsplayer of matchvenueumpire 1umpire 2
id
1IPL-2017Hyderabad05-04-2017Sunrisers HyderabadRoyal Challengers BangaloreRoyal Challengers Bangalorefieldnormal0Sunrisers Hyderabad350Yuvraj SinghRajiv Gandhi International Stadium, UppalAY DandekarNJ Llong
2IPL-2017Pune06-04-2017Mumbai IndiansRising Pune SupergiantRising Pune Supergiantfieldnormal0Rising Pune Supergiant07SPD SmithMaharashtra Cricket Association StadiumA Nand KishoreS Ravi
3IPL-2017Rajkot07-04-2017Gujarat LionsKolkata Knight RidersKolkata Knight Ridersfieldnormal0Kolkata Knight Riders010CA LynnSaurashtra Cricket Association StadiumNitin MenonCK Nandan
4IPL-2017Indore08-04-2017Rising Pune SupergiantKings XI PunjabKings XI Punjabfieldnormal0Kings XI Punjab06GJ MaxwellHolkar Cricket StadiumAK ChaudharyC Shamshuddin
5IPL-2017Bangalore08-04-2017Royal Challengers BangaloreDelhi DaredevilsRoyal Challengers Bangalorebatnormal0Royal Challengers Bangalore150KM JadhavM Chinnaswamy StadiumNaNNaN
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Seasoncitydateteam_1team_2toss_winnertoss decisionresultdl_appliedwinnerwin_by_runswin_by_wicketsplayer_of_matchvenueumpire_1umpire_2
id
1IPL-2017Hyderabad05-04-2017Sunrisers HyderabadRoyal Challengers BangaloreRoyal Challengers Bangalorefieldnormal0Sunrisers Hyderabad350Yuvraj SinghRajiv Gandhi International Stadium, UppalAY DandekarNJ Llong
2IPL-2017Pune06-04-2017Mumbai IndiansRising Pune SupergiantRising Pune Supergiantfieldnormal0Rising Pune Supergiant07SPD SmithMaharashtra Cricket Association StadiumA Nand KishoreS Ravi
3IPL-2017Rajkot07-04-2017Gujarat LionsKolkata Knight RidersKolkata Knight Ridersfieldnormal0Kolkata Knight Riders010CA LynnSaurashtra Cricket Association StadiumNitin MenonCK Nandan
4IPL-2017Indore08-04-2017Rising Pune SupergiantKings XI PunjabKings XI Punjabfieldnormal0Kings XI Punjab06GJ MaxwellHolkar Cricket StadiumAK ChaudharyC Shamshuddin
5IPL-2017Bangalore08-04-2017Royal Challengers BangaloreDelhi DaredevilsRoyal Challengers Bangalorebatnormal0Royal Challengers Bangalore150KM JadhavM Chinnaswamy StadiumNaNNaN
\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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Seasoncitydateteam_1team 2toss_winnertoss_decisionresultdl_appliedwinnerwin_by_runswin by wicketsplayer of matchvenueumpire 1umpire 2
id
1IPL-2017Hyderabad05-04-2017Sunrisers HyderabadRoyal Challengers BangaloreRoyal Challengers Bangalorefieldnormal0Sunrisers Hyderabad350Yuvraj SinghRajiv Gandhi International Stadium, UppalAY DandekarNJ Llong
2IPL-2017Pune06-04-2017Mumbai IndiansRising Pune SupergiantRising Pune Supergiantfieldnormal0Rising Pune Supergiant07SPD SmithMaharashtra Cricket Association StadiumA Nand KishoreS Ravi
3IPL-2017Rajkot07-04-2017Gujarat LionsKolkata Knight RidersKolkata Knight Ridersfieldnormal0Kolkata Knight Riders010CA LynnSaurashtra Cricket Association StadiumNitin MenonCK Nandan
4IPL-2017Indore08-04-2017Rising Pune SupergiantKings XI PunjabKings XI Punjabfieldnormal0Kings XI Punjab06GJ MaxwellHolkar Cricket StadiumAK ChaudharyC Shamshuddin
5IPL-2017Bangalore08-04-2017Royal Challengers BangaloreDelhi DaredevilsRoyal Challengers Bangalorebatnormal0Royal Challengers Bangalore150KM JadhavM Chinnaswamy StadiumNaNNaN
\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,9 +782,214 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Seasoncitydateteam_1team_2toss_winnertoss_decisionresultdl_appliedwinnerwin_by_runswin_by_wicketsplayer_of_matchvenueumpire_1umpire_2
id
1IPL-2017Hyderabad05-04-2017Sunrisers HyderabadRoyal Challengers BangaloreRoyal Challengers Bangalorefieldnormal0Sunrisers Hyderabad350Yuvraj SinghRajiv Gandhi International Stadium, UppalAY DandekarNJ Llong
2IPL-2017Pune06-04-2017Mumbai IndiansRising Pune SupergiantRising Pune Supergiantfieldnormal0Rising Pune Supergiant07SPD SmithMaharashtra Cricket Association StadiumA Nand KishoreS Ravi
3IPL-2017Rajkot07-04-2017Gujarat LionsKolkata Knight RidersKolkata Knight Ridersfieldnormal0Kolkata Knight Riders010CA LynnSaurashtra Cricket Association StadiumNitin MenonCK Nandan
4IPL-2017Indore08-04-2017Rising Pune SupergiantKings XI PunjabKings XI Punjabfieldnormal0Kings XI Punjab06GJ MaxwellHolkar Cricket StadiumAK ChaudharyC Shamshuddin
5IPL-2017Bangalore08-04-2017Royal Challengers BangaloreDelhi DaredevilsRoyal Challengers Bangalorebatnormal0Royal Challengers Bangalore150KM JadhavM Chinnaswamy StadiumNaNNaN
\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": [ "df.columns = list(map(lambda l: l.replace(' ', '_'), list(df.columns)))\n", "df.head()" @@ -209,7 +1029,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -220,7 +1040,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -234,9 +1054,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "96\n", + "Duration: 14.108283996582031 seconds\n" + ] + } + ], "source": [ "start = time.time()\n", "verified_elements = []\n", @@ -258,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.048497915267944336 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))" @@ -277,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.013466119766235352 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))" @@ -387,7 +1236,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -405,7 +1254,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -421,7 +1270,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -439,24 +1288,9 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "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", - "\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" - ] - } - ], + "outputs": [], "source": [ "!pytest test_abilities.py" ] From 4bdb56205c18415c03ad5ba18b594016bfd68643 Mon Sep 17 00:00:00 2001 From: advaith3600 Date: Sat, 9 Jan 2021 21:38:49 +0530 Subject: [PATCH 4/7] step 4 completed --- Python-ifed.ipynb | 2 +- step_4.py | 63 +++++++++++++++++++++++ subset_elemets.txt => subset_elements.txt | 0 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 step_4.py rename subset_elemets.txt => subset_elements.txt (100%) diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index 061041a..f6f084d 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -1044,7 +1044,7 @@ "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", 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 From 9eefcdaf108532efe6be8da28dcf3f552416f6bf Mon Sep 17 00:00:00 2001 From: advaith3600 Date: Sat, 9 Jan 2021 22:00:10 +0530 Subject: [PATCH 5/7] step 5 completed --- Python-ifed.ipynb | 20 ++++++++++++++++++-- nearest_square.py | 5 +++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 nearest_square.py diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index f6f084d..c6d4baa 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -1180,9 +1180,25 @@ }, { "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\r\n", + "platform darwin -- Python 3.8.3, pytest-5.4.3, py-1.9.0, pluggy-0.13.1\r\n", + "rootdir: /Users/advaith/Sites/Python-ifed-challenge\r\n", + "\u001b[1mcollecting ... \u001b[0m\u001b[1m\r", + "collected 4 items \u001b[0m\r\n", + "\r\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\r\n", + "\r\n", + "\u001b[32m============================== \u001b[32m\u001b[1m4 passed\u001b[0m\u001b[32m in 0.01s\u001b[0m\u001b[32m ===============================\u001b[0m\r\n" + ] + } + ], "source": [ "! pytest test_nearest_square.py" ] 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 From d7445bc2d980f642c4a2b5584664799f24242c4a Mon Sep 17 00:00:00 2001 From: advaith3600 Date: Sun, 10 Jan 2021 11:24:56 +0530 Subject: [PATCH 6/7] Completed challenge 2 --- Python-ifed.ipynb | 159 +++++++++++++++++++++++++++++++++++++++------- ability.py | 75 ++++++++++++++++++++++ 2 files changed, 211 insertions(+), 23 deletions(-) create mode 100644 ability.py diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index c6d4baa..42cc1a8 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -1062,7 +1062,7 @@ "output_type": "stream", "text": [ "96\n", - "Duration: 14.108283996582031 seconds\n" + "Duration: 16.00716996192932 seconds\n" ] } ], @@ -1095,7 +1095,7 @@ "output_type": "stream", "text": [ "96\n", - "Duration: 0.048497915267944336 seconds\n" + "Duration: 0.05529594421386719 seconds\n" ] } ], @@ -1124,7 +1124,7 @@ "output_type": "stream", "text": [ "96\n", - "Duration: 0.013466119766235352 seconds\n" + "Duration: 0.013680219650268555 seconds\n" ] } ], @@ -1187,15 +1187,14 @@ "name": "stdout", "output_type": "stream", "text": [ - "\u001b[1m============================= test session starts ==============================\u001b[0m\r\n", - "platform darwin -- Python 3.8.3, pytest-5.4.3, py-1.9.0, pluggy-0.13.1\r\n", - "rootdir: /Users/advaith/Sites/Python-ifed-challenge\r\n", - "\u001b[1mcollecting ... \u001b[0m\u001b[1m\r", - "collected 4 items \u001b[0m\r\n", - "\r\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\r\n", - "\r\n", - "\u001b[32m============================== \u001b[32m\u001b[1m4 passed\u001b[0m\u001b[32m in 0.01s\u001b[0m\u001b[32m ===============================\u001b[0m\r\n" + "\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" ] } ], @@ -1252,11 +1251,46 @@ }, { "cell_type": "code", - "execution_count": null, + "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')" ] }, { @@ -1270,11 +1304,44 @@ }, { "cell_type": "code", - "execution_count": null, + "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)" ] }, { @@ -1286,11 +1353,42 @@ }, { "cell_type": "code", - "execution_count": null, + "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)" ] }, { @@ -1304,9 +1402,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "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\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 3.85s\u001b[0m\u001b[32m ===============================\u001b[0m\n" + ] + } + ], "source": [ "!pytest test_abilities.py" ] diff --git a/ability.py b/ability.py new file mode 100644 index 0000000..00da5f5 --- /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) From 9ac3e108ad2f0fb6bbd9dd989241a735d62c60d5 Mon Sep 17 00:00:00 2001 From: advaith3600 Date: Sun, 10 Jan 2021 13:30:50 +0530 Subject: [PATCH 7/7] Completed Extra Challenge --- ability.py | 10 +++++----- pokedex.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 pokedex.py diff --git a/ability.py b/ability.py index 00da5f5..9747eb2 100644 --- a/ability.py +++ b/ability.py @@ -68,8 +68,8 @@ def ability(pokemon): return list(map(lambda a: a['ability']['name'], abilities)) -types = pokeType('pidgeot') -print() -double_damage_types = damageFrom(types) -print() -doubleDamageTypesPokemon(double_damage_types) +# types = pokeType('pidgeot') +# print() +# double_damage_types = damageFrom(types) +# print() +# doubleDamageTypesPokemon(double_damage_types) 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()