-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab3.py
More file actions
37 lines (30 loc) · 832 Bytes
/
Lab3.py
File metadata and controls
37 lines (30 loc) · 832 Bytes
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
36
37
import pandas as pd
import numpy as np
import statistics
# reading the file and selecting the coloum named "BMI"
filename = "diabetes.csv"
data = pd.read_csv(filename)
col_1 = data.BMI
# creating array
array = np.array(col_1)
# sort the array
array = np.sort(array)
# create bins
bin1 = np.zeros((30, 5))
bin2 = np.zeros((30, 5))
# Bin mean
for i in range(0, 150, 5):
k = int(i / 5)
mean = (array[i] + array[i + 1] + array[i + 2] + array[i + 3] + array[i + 4]) / 5
for j in range(5):
bin1[k, j] = mean
print("Bin Mean: \n", bin1)
# Bin boundaries
for i in range(0, 150, 5):
k = int(i / 5)
for j in range(5):
if (array[i + j] - array[i]) < (array[i + 4] - array[i + j]):
bin2[k, j] = array[i]
else:
bin2[k, j] = array[i + 4]
print("Bin Boundaries: \n", bin2)