<jupyter_start><jupyter_text>Practice Exercise 1 This is the first exercise for Pandas. You are provided with 2 fictional dataframes based on Indian Premier League (IPL). The first dataframe contains the data for all the teams who participated in the year 2018. In the second dataframe, the data is for the year 2017.<jupyter_code># import the required libraries - numpy and pandas
import pandas as pd
import numpy as np
import matplotlib.pyplot as pltManash<jupyter_output><empty_output><jupyter_text>Data Dictionary-  Team: Team name-  Matches: Total number of matches played-  Won: Number of matches won-  Lost: Number of matches lost-  Tied': Number of matches tied-  N/R: Number of matches with no result-  NRR: Net run rate (Rate of scoring the runs)-  For: Sum of runs scored by the team against other teams-  Against: Sum of runs scored by the opposite playing teams<jupyter_code># ipl18 contains the data for 2018
ipl18 = pd.DataFrame({'Team': ['SRH', 'CSK', 'KKR', 'RR', 'MI', 'RCB', 'KXIP', 'DD'],
                         'Matches': [14, 14, 14, 14, 14, 14, 14, 14],
                         'Won': [9, 9, 8, 7, 6, 6, 6, 5],
                         'Lost': [5, 5, 6, 7, 8, 8, 8, 9],
                         'Tied': [0, 0, 0, 0, 0, 0, 0, 0],
                         'N/R': [0, 0, 0, 0, 0, 0, 0, 0],
                         'NRR': [0.284, 0.253, -0.070, -0.250, 0.317, 0.129, -0.502, -0.222],
                         'For': [2230, 2488, 2363, 2130, 2380, 2322, 2210, 2297],
                         'Against': [2193, 2433, 2425, 2141, 2282, 2383, 2259, 2304]},
                         index = range(1,9)
                    )
# print the entire dataframe to check the entries
ipl18
# ipl17 contains the data for 2017
ipl17 = pd.DataFrame({'Team': ['MI', 'RPS', 'SRH', 'KKR', 'KXIP', 'DD', 'GL', 'RCB'],
                         'Matches': [14, 14, 14, 14, 14, 14, 14, 14],
                         'Won': [10, 9, 8, 8, 7, 6, 4, 3],
                         'Lost': [4, 5, 5, 6, 7, 8, 10, 10],
                         'Tied': [0, 0, 0, 0, 0, 0, 0, 0],
                         'N/R': [0, 0, 1, 0, 0, 0, 0, 1],
                         'NRR': [0.784, 0.176, 0.469, 0.641, 0.123, -0.512, -0.412, -1.299],
                         'For': [2407, 2180, 2221, 2329, 2207, 2219, 2406, 1845],
                         'Against': [2242, 2165, 2118, 2300, 2229, 2255, 2472, 2033]},
                         index = range(1,9)
                    )
# print the entire dataframe to check the entries
ipl17<jupyter_output><empty_output><jupyter_text>As a part of this exercise, solve the questions that are provided below. There are few tasks that you will have to perform to be able to answer the questions.**Task 1**You have to create a new column '*Points*' in both the dataframes that stores the total points scored by each team. The following scoring system is used to calculate the points of a team:-  Win: 2 points-  Loss: 0 points-  Tie: 1 point-  N/R (no result): 1 point<jupyter_code># Type your code here
ipl17['Points'] = ((ipl17['Won'] * 2) + (ipl17['Tied'] * 1) + (ipl17['N/R'] * 1))
ipl18['Points'] = ((ipl18['Won'] * 2) + (ipl18['Tied'] * 1) + (ipl18['N/R'] * 1))
ipl17
ipl18<jupyter_output><empty_output><jupyter_text>Q1: Extract Top Four TeamsWhich of the following commands can you use to extract the top 4 teams in the dataset ‘ipl18’ with just the ‘Team’ and ‘Points’ column?-  ipl18.loc [0:3, [‘Team’, ‘Points’]]-  ipl18.loc [1:4, [‘Team’, ‘Points’]]-  ipl18.loc [0:4, [‘Team’, ‘Points’]]-  ipl18.loc [1:3, [‘Team’, ‘Points’]]<jupyter_code># Type your code here
ipl18.loc[0:3, ['Team', 'Points']]
ipl18.loc [1:4, ['Team', 'Points']]<jupyter_output><empty_output><jupyter_text>Q2: Filtering based on conditionsSuppose in ‘ipl18’, you want to filter out the teams that have an NRR greater than zero, and for which the ‘For’ score exceeds the ‘Against’ score, i.e. both the conditions should be satisfied. Which teams will be left after you perform the above filtration? (Run the commands on the Python Notebook provided, rather than performing a manual calculation)-  CSK, MI-  SRH, CSK, MI-  SRH, CSK, RCB-  SRH, CSK, MI, RCB<jupyter_code># Type your code here
ipl18[(ipl18['NRR'] > 0) & (ipl18['For'] > ipl18['Against'])]
ipl18.loc[(ipl18.NRR > 0) & (ipl18.For > ipl18.Against), ]<jupyter_output><empty_output><jupyter_text>Q3: Operations on multiple dataframesIf all the stats are taken for both ‘ipl17’ and ‘ipl18’, which team with its total points greater than 25 will have the highest win percentage?-  KKR-  CSK-  RPS-  SRH<jupyter_code># Type your code here
iplFinal = ipl17.merge(ipl18,on=['Team'])
iplFinal['totalPoints'] = iplFinal.Points_x + iplFinal.Points_y
iplFinal['winPercentage'] = (iplFinal.totalPoints / 56) * 100
iplFinal[iplFinal['totalPoints'] > 25]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.141139896373057, 'fraction_numerical': 0.08766839378238342, 'mean_word_length': 2.8638911128903124, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '291450', 'license': 'MIT', 'n_tokens_mistral': 2000, 'n_tokens_neox': 1629, 'n_words': 616, 'path': 'Data Science/Pandas/Practice+Exercise+1+IPL.ipynb', 'repo_name': 'manash-ranjan-khamari/notebook', 'size': '4825'}