-
Notifications
You must be signed in to change notification settings - Fork 253
Expand file tree
/
Copy pathbuild.py
More file actions
36 lines (25 loc) · 1.14 KB
/
build.py
File metadata and controls
36 lines (25 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# %load q06_get_unique_matches_count/build.py
# Default imports
from greyatomlib.python_intermediate.q05_read_csv_data.build import read_ipl_data_csv
path = 'data/ipl_matches_small.csv'
# Enter Code Here
from greyatomlib.python_intermediate.q05_read_csv_data.build import read_ipl_data_csv
path = 'data/ipl_matches_small.csv'
import numpy as np
import csv
def get_unique_matches_count():
no_of_matches_played = 0
with open(path,'r') as csvfile:
csvreader = csv.reader(csvfile)
data = [row for row in csvreader]
np_ipl_data = np.asarray(data)
headers = tuple(np_ipl_data[0])
#slicing main ndarray into required ndarray
match_codes = np_ipl_data[1:,[headers.index('match_code')]]
#reshaping ndarray from 2d to 1d to make a list
match_codes_array = match_codes.reshape(np.product(match_codes.shape))
#converting 1d array to a list and then removing duplicates to get unique values
match_codes_set = set(match_codes_array.tolist())
#length of the set will be the total number of matches played
no_of_matches_played = len(match_codes_set)
return no_of_matches_played