-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_visualization.py
More file actions
114 lines (94 loc) · 3.72 KB
/
Copy pathdata_visualization.py
File metadata and controls
114 lines (94 loc) · 3.72 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# -*- coding: utf-8 -*-
"""Data-Visualization.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1_sMQYK0g67v2_HWwsPi8K2QOskZNc17j
"""
# Create a dataset representing patient records.
# Add 6 patients
# [Patient name, BP, SugarLevel, HR]
patients = [
['Aakash', 68, 50, 41],
['Fahad', 102, 100, 92],
['Munim', 95, 90, 59],
['Rohaan', 88, 84, 67],
['Aazan', 106, 78, 88],
['Manam', 99, 95, 90]
]
# Compute an overall health score (average)
# Add it as a new column in your dataset
import pandas as pd
df = pd.DataFrame(patients, columns=[ 'Patient Name', 'Blood Pressure', 'Sugar Level', 'Heart Rate'])
df['Health Score'] = df[['Blood Pressure', 'Sugar Level', 'Heart Rate']].mean(axis=1)
print(df)
# Overall clinic health average
avghealth = df['Health Score'].mean()
print("Clinic health average: ",avghealth)
print("_________________")
# Patients with highest and lowest health scores
highest_patient = df.loc[df['Health Score'].idxmax(), 'Patient Name']
highest_score = df['Health Score'].max()
lowest_patient = df.loc[df['Health Score'].idxmin(), 'Patient Name']
lowest_score = df['Health Score'].min()
print("Patient with highest health score: ",highest_patient, highest_score)
print("Patient with lowest health score: ",lowest_patient, lowest_score)
print("________________")
# Patients above average (healthier)
# Patients below average (need attention)
highpatients = df[df['Health Score']> avghealth]
print("Healthier Patients : ")
print("_______________________________________")
print(highpatients)
print("_______________________________________")
lowpatients = df[df['Health Score']< avghealth]
print("Need Attention Patients : ")
print("_______________________________________")
print(lowpatients)
# RULES:
# - BP: Normal range 90-120
# - Sugar Level: Normal range 70-100
# - Heart Rate: Normal range 60-100
# 3 Groups: Stable, Monitor, Critical
def categorize_patient(row):
bp_normal = (90 <= row['Blood Pressure'] <= 120)
sugar_normal = (70 <= row['Sugar Level'] <= 100)
hr_normal = (60 <= row['Heart Rate'] <= 100)
abnormal = sum([not bp_normal, not sugar_normal, not hr_normal])
if abnormal == 3:
return "Critical"
elif abnormal >= 1:
return "Monitor"
else:
return "Stable"
# Apply categorization
df['Category'] = df.apply(categorize_patient, axis=1)
print(df[['Patient Name', 'Blood Pressure', 'Sugar Level', 'Heart Rate', 'Health Score', 'Category']])
# Total
print(df['Category'].value_counts())
import matplotlib.pyplot as plt
colors = {'Stable': 'green', 'Monitor': 'orange', 'Critical': 'red'}
patient_clr =[colors[cat] for cat in df['Category']]
plt.figure(figsize=(12, 6))
bars= plt.bar(df['Patient Name'], df['Health Score'], color=patient_clr)
plt.title('Patient Health Assessment Dashboard', fontsize=16)
plt.xlabel('Patient Name', fontsize=10)
plt.ylabel('Health Score', fontsize=10)
for bar in bars:
yval = bar.get_height()
plt.text(bar.get_x() + bar.get_width()/2, yval, round(yval, 2), ha='center', va='bottom')
from matplotlib.patches import Patch
legend_elements = [Patch(facecolor='green', label='Stable'),
Patch(facecolor='orange', label='Monitor'),
Patch(facecolor='red', label='Critical')]
plt.legend(handles=legend_elements , loc='upper left')
plt.ylim(0, 120)
plt.show()
goodpatients = df[(df['Category'] == 'Stable') & (df['Health Score'] > avghealth)]
print("Good Patients : ")
print("_______________________________________")
print(goodpatients)
print("_______________________________________")
reqrttmnt = df[df['Category'].isin(['Monitor', 'Critical'])]
print("These Patients need attention: ")
print("_______________________________________")
print(reqrttmnt)