From 53e62f508caa4774a14bd81524dae9d0ecfdce30 Mon Sep 17 00:00:00 2001 From: preetiail Date: Fri, 5 Oct 2018 16:48:53 +0000 Subject: [PATCH 1/5] Done --- q01_zeros_array/build.py | 6 ++++++ q03_create_3d_array/build.py | 11 ++++++++++- q04_read_csv_data_to_ndarray/build.py | 12 ++++++++++-- q05_read_csv_data/build.py | 7 ++++++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/q01_zeros_array/build.py b/q01_zeros_array/build.py index 5501f7a..4f82a19 100644 --- a/q01_zeros_array/build.py +++ b/q01_zeros_array/build.py @@ -1,8 +1,14 @@ +# %load q01_zeros_array/build.py # Default Imports import sys, os sys.path.append(os.path.join(os.path.dirname(os.curdir), '..' )) import numpy as np +def array_zeros(): # Your solution + arrayresult=np.zeros((3,4,2)) + return arrayresult + + diff --git a/q03_create_3d_array/build.py b/q03_create_3d_array/build.py index 7bb6e2f..429dfec 100644 --- a/q03_create_3d_array/build.py +++ b/q03_create_3d_array/build.py @@ -1,4 +1,13 @@ +# %load q03_create_3d_array/build.py # Default Imports import numpy as np -# Enter solution here \ No newline at end of file +# Enter solution here +def create_3d_array(): + Count=3*3*3 + l1=list(range(0,Count,1)) + arr1=np.array(l1) + arr2=arr1.reshape(3,3,3) + print(arr2.shape) + return arr2 + diff --git a/q04_read_csv_data_to_ndarray/build.py b/q04_read_csv_data_to_ndarray/build.py index fb71e6e..c35d878 100644 --- a/q04_read_csv_data_to_ndarray/build.py +++ b/q04_read_csv_data_to_ndarray/build.py @@ -1,5 +1,13 @@ +# %load q04_read_csv_data_to_ndarray/build.py # Default Imports import numpy as np -path = "./data/ipl_matches_small.csv" +path = './data/ipl_matches_small.csv' + +# Enter code here + +def read_csv_data_to_ndarray(path , dtype = np.float64): + result = np.genfromtxt(path,skip_header = 1 , delimiter = ',' , dtype= dtype) + return result +print(read_csv_data_to_ndarray(path)) + -# Enter code here \ No newline at end of file diff --git a/q05_read_csv_data/build.py b/q05_read_csv_data/build.py index 5c70e6e..ba72d29 100644 --- a/q05_read_csv_data/build.py +++ b/q05_read_csv_data/build.py @@ -1,4 +1,9 @@ +# %load q05_read_csv_data/build.py # Default imports import numpy as np +path = './data/ipl_matches_small.csv' +def read_ipl_data_csv(path,dtype): + ipl_matches_array=np.genfromtxt(path,delimiter= ',',dtype='str') + return(ipl_matches_array) + -# Enter code here \ No newline at end of file From c2467e2b169291ce7173759b144df67fe3f71d7c Mon Sep 17 00:00:00 2001 From: preetiail Date: Fri, 5 Oct 2018 17:01:50 +0000 Subject: [PATCH 2/5] Done --- q05_read_csv_data/build.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/q05_read_csv_data/build.py b/q05_read_csv_data/build.py index ba72d29..702f7bf 100644 --- a/q05_read_csv_data/build.py +++ b/q05_read_csv_data/build.py @@ -3,7 +3,9 @@ import numpy as np path = './data/ipl_matches_small.csv' def read_ipl_data_csv(path,dtype): - ipl_matches_array=np.genfromtxt(path,delimiter= ',',dtype='str') + ipl_matches_array=np.genfromtxt(path,delimiter= ',',skip_header=1,dtype=dtype) return(ipl_matches_array) - +read_ipl_data_csv(path,'|S50') + + From 1943248ac2265f367b6325c3b581b4a419e41c9e Mon Sep 17 00:00:00 2001 From: preetiail Date: Fri, 5 Oct 2018 17:48:33 +0000 Subject: [PATCH 3/5] Done --- q06_get_unique_matches_count/build.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/q06_get_unique_matches_count/build.py b/q06_get_unique_matches_count/build.py index 014497e..0f6a047 100644 --- a/q06_get_unique_matches_count/build.py +++ b/q06_get_unique_matches_count/build.py @@ -1,5 +1,14 @@ +# %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' +import numpy as np +import pandas as pd + +def get_unique_matches_count(): + data2=pd.read_csv(path,delimiter=',',dtype='|S50') + ipl_matches_array=data2.iloc[:,0:1].nunique() + return(ipl_matches_array[0]) +get_unique_matches_count() + -# Enter Code Here From 990dfe9800a1edb0ae8381498265b663123341b6 Mon Sep 17 00:00:00 2001 From: preetiail Date: Sun, 7 Oct 2018 15:36:52 +0000 Subject: [PATCH 4/5] Done --- q07_get_unique_teams_set/build.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/q07_get_unique_teams_set/build.py b/q07_get_unique_teams_set/build.py index 17fefd2..918c046 100644 --- a/q07_get_unique_teams_set/build.py +++ b/q07_get_unique_teams_set/build.py @@ -1,5 +1,13 @@ +# %load q07_get_unique_teams_set/build.py # Default imports from greyatomlib.python_intermediate.q05_read_csv_data.build import read_ipl_data_csv -path = "data/ipl_matches_small.csv" +path = 'data/ipl_matches_small.csv' +import numpy as np +import pandas as pd + +def get_unique_teams_set(): + df=read_ipl_data_csv(path,dtype='|S50') + return(set(np.unique(df[:,3])).union(np.unique(df[:,4]))) +get_unique_teams_set() + -# Enter Code Here From a8306e8d21a85b03e1bba927cb98bf48b292e324 Mon Sep 17 00:00:00 2001 From: preetiail Date: Sun, 7 Oct 2018 15:45:48 +0000 Subject: [PATCH 5/5] Done --- q08_get_total_extras/build.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/q08_get_total_extras/build.py b/q08_get_total_extras/build.py index 95890c1..71e7b74 100644 --- a/q08_get_total_extras/build.py +++ b/q08_get_total_extras/build.py @@ -1,7 +1,14 @@ +# %load q08_get_total_extras/build.py # Default Imports from greyatomlib.python_intermediate.q05_read_csv_data.build import read_ipl_data_csv import numpy as np -path = 'data/ipl_matches_small.csv' +path = './data/ipl_matches_small.csv' + +# Enter Code Here +def get_total_extras(): + array1=np.genfromtxt(path,delimiter=',') + result=np.sum(array1[:,17][~np.isnan(array1[:,17])]) + return(np.int64(result)) +get_total_extras() -# Enter Code Here \ No newline at end of file