From 31319655fe5902a99b4375d2591b8efdbbaae780 Mon Sep 17 00:00:00 2001 From: aj02 Date: Sun, 11 Feb 2018 17:56:45 +0000 Subject: [PATCH 1/7] Done --- q01_read_data/build.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/q01_read_data/build.py b/q01_read_data/build.py index e13d2f74..b81501e9 100644 --- a/q01_read_data/build.py +++ b/q01_read_data/build.py @@ -1,3 +1,4 @@ +# %load q01_read_data/build.py import yaml def read_data(): @@ -5,8 +6,7 @@ def read_data(): # import the csv file into `data` variable # You can use this path to access the CSV file: '../data/ipl_match.yaml' # Write your code here - - data = - + with open( './data/ipl_match.yaml', 'r') as stream: + data = yaml.load(stream) # return data variable return data From 780216645e9907fddc21dac79a5860f4884a160f Mon Sep 17 00:00:00 2001 From: aj02 Date: Sun, 11 Feb 2018 18:18:51 +0000 Subject: [PATCH 2/7] Done --- q02_teams/build.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/q02_teams/build.py b/q02_teams/build.py index 3cf9d3cf..c97dbb6a 100644 --- a/q02_teams/build.py +++ b/q02_teams/build.py @@ -1,3 +1,4 @@ +# %load q02_teams/build.py # default imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() @@ -6,6 +7,8 @@ def teams(data=data): # write your code here - #teams = + teams = data['info']['teams'] return teams +r = teams(data) +print r From 3f83536c74f071617d75560e7590e6e0a78e6d31 Mon Sep 17 00:00:00 2001 From: aj02 Date: Sun, 11 Feb 2018 18:31:58 +0000 Subject: [PATCH 3/7] Done --- q03_first_batsman/build.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/q03_first_batsman/build.py b/q03_first_batsman/build.py index 84984081..d452835d 100644 --- a/q03_first_batsman/build.py +++ b/q03_first_batsman/build.py @@ -1,4 +1,6 @@ +# %load q03_first_batsman/build.py # Default Imports +import pandas as pd from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() @@ -6,8 +8,7 @@ def first_batsman(data=data): # Write your code here - - - - + name = data['innings'][0]['1st innings']['deliveries'][0][0.1]['batsman'] return name +r = first_batsman() +print r From 000d9c2d43e09bc3003ed6589bbccb0d4ac74121 Mon Sep 17 00:00:00 2001 From: aj02 Date: Sun, 11 Feb 2018 18:51:17 +0000 Subject: [PATCH 4/7] Done --- q04_count/build.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/q04_count/build.py b/q04_count/build.py index 6cf3dcbc..268acd04 100644 --- a/q04_count/build.py +++ b/q04_count/build.py @@ -1,11 +1,19 @@ +# %load q04_count/build.py # Default Imports +import pandas as pd from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() # Your Solution Here def deliveries_count(data=data): - + count = 0 # Your code here - - + first_inning = data['innings'][0]['1st innings']['deliveries'] + #return pd.DataFrame(first_inning) + for each_delivery in first_inning: + for each_ball, each_ball_detail in each_delivery.items(): + if each_ball_detail['batsman'] == 'RT Ponting': + count+=1 return count + +deliveries_count(data) From 553761a097163cb3f058461e2730198423583279 Mon Sep 17 00:00:00 2001 From: aj02 Date: Sun, 11 Feb 2018 18:58:56 +0000 Subject: [PATCH 5/7] Done --- q05_runs/build.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/q05_runs/build.py b/q05_runs/build.py index a250631a..765e23db 100644 --- a/q05_runs/build.py +++ b/q05_runs/build.py @@ -1,3 +1,4 @@ +# %load q05_runs/build.py # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() @@ -7,6 +8,12 @@ def BC_runs(data): # Write your code here - + runs = 0 + first_inning = data['innings'][0]['1st innings']['deliveries'] + for each_delivery in first_inning: + for each_ball, each_ball_detail in each_delivery.items(): + if each_ball_detail['batsman'] == 'BB McCullum': + runs += each_ball_detail['runs']['batsman'] return(runs) +BC_runs(data) From fbbba36362849fb53e8ea7997892e04bdcf0de4d Mon Sep 17 00:00:00 2001 From: aj02 Date: Sun, 11 Feb 2018 19:09:51 +0000 Subject: [PATCH 6/7] Done --- q06_bowled_players/build.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/q06_bowled_players/build.py b/q06_bowled_players/build.py index 914cb6d2..496bd386 100644 --- a/q06_bowled_players/build.py +++ b/q06_bowled_players/build.py @@ -1,3 +1,4 @@ +# %load q06_bowled_players/build.py # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() @@ -6,6 +7,12 @@ def bowled_out(data=data): # Write your code here - + bowled_players = [] + first_inning = data['innings'][1]['2nd innings']['deliveries'] + for each_delivery in first_inning: + for each_ball, each_ball_detail in each_delivery.items(): + if each_ball_detail.get('wicket', {}).get('kind') == 'bowled': + bowled_players.append(each_ball_detail['batsman']) return bowled_players +bowled_out(data) From 77ffb9b18042f00df65b344ab9a79b5a2954a2da Mon Sep 17 00:00:00 2001 From: aj02 Date: Sun, 11 Feb 2018 19:26:09 +0000 Subject: [PATCH 7/7] Done --- q07_extras/build.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/q07_extras/build.py b/q07_extras/build.py index cdeb803b..1ab87697 100644 --- a/q07_extras/build.py +++ b/q07_extras/build.py @@ -1,3 +1,4 @@ +# %load q07_extras/build.py # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() @@ -6,9 +7,22 @@ def extras_runs(data=data): # Write your code here - - - difference = + first_extras = 0 + first_inning = data['innings'][0]['1st innings']['deliveries'] + for each_delivery in first_inning: + for each_ball, each_ball_detail in each_delivery.items(): + #print each_ball_detail['runs']['extras'] + if each_ball_detail['runs']['extras'] > 0: + first_extras += 1 + #print first_extras + second_extras = 0 + second_inning = data['innings'][1]['2nd innings']['deliveries'] + for each_delivery in second_inning: + for each_ball, each_ball_detail in each_delivery.items(): + if each_ball_detail['runs']['extras'] > 0: + second_extras += 1 + difference = abs(second_extras - first_extras) return difference +extras_runs(data)