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 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 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 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) 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) 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) 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)