Professional Documents
Culture Documents
import numpy as np
a = np.array([[1, 4, 2],
[3, 4, 6],
[0, -1, 5]])
In this Case Study, you are expected to apply the NumPy python library
to explore a dataset. The dataset we'll be using is a medical dataset
with information about some patients on metrics like glucose, insulin
levels, and other metrics related to diabetes. The assignment will
serve two primary objectives - (a) practice NumPy on a realistic task,
and (b) learn how to get a feel for a large dataset (also known as
data cleaning and data exploration).
Dataset description
Perform the following based on a given Data Set using Python Library
NUMPY:
In this dataset, Outcome = 0 denotes that the patient does not have
diabetes. And Outcome = 1 denotes that the patient has diabetes.
8. For how many patients is at-least one of the features missing? (Be
careful that it is okay for someone to be Pregnant 0 times).
11. What is the average glucose level among the diabetes patients?
12. What is the average glucose level among the non-diabetic people?
ANSWERS
CODE
#################################################### Question 1
import numpy as np
####################################################### Question 2
a = np.array([[1, 4, 2],
[3, 4,6],
[0, -1, 5]])
# Sorted array
print ("Array elements in sorted order:\n", np.sort(a, axis = None))
###### Question 1
# Importing dataset
dbdata = np.loadtxt('C:/Users/Sarthak Kaushik/Desktop/diabetes.csv',
skiprows=1, delimiter=',')
OUTPUT
Largest element is 9
Row-wise max elements: [6 7 9]
Row-wise min elements: [1 2 1]
Column-wise max elements: [4 7 9]
Column-wise min elements: [1 1 2]
Sum of all array elements: 38
Cumulative sum along each row:
[[ 1 6 12]
[ 4 11 13]
[ 3 4 13]]
Array elements in sorted order:
[-1 0 1 2 3 4 4 5 6]
Row-wise sorted array:
[[ 1 2 4]
[ 3 4 6]
[-1 0 5]]
Column wise sort by applying merge-sort:
[[ 0 -1 2]
[ 1 4 5]
[ 3 4 6]]