-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathZeeshan.Latif_Karachi_Python_Assignment.py
62 lines (39 loc) · 1.33 KB
/
Zeeshan.Latif_Karachi_Python_Assignment.py
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
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 17 09:36:51 2017
@author: Zeeshan.Latif
"""
import pandas
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('ggplot')
df=pandas.read_csv("E:/DIH/chronic_kidney_disease_updated.csv")
#print column names
print(list(df) )
#print first 5 rows
print(df.head())
df.drop(df.index[[0]], inplace=True)
#df.drop('Unnamed: 0', axis=1, inplace=True)
print(df.dm.unique() )
def replace(tup, df):
for i in tup:
df.replace(to_replace=i, value=np.nan, inplace=True)
def cleandf(df):
df=df.applymap(lambda x: str(x).strip())
return df
df=cleandf(df)
replace(( "\t", " ", "?"), df)
print(df.dm.unique() )
numeric_columns= ['age', 'bp', 'bgr', 'bu', 'sc', 'sod', 'pot', 'hemo', 'pcv', 'wbcc', 'rbcc']
for i in numeric_columns:
df[i] = pandas.to_numeric(df[i], errors='coerce')
print(df[['pc','al']])
df.rename(columns={'class': 'Class'}, inplace=True)
ckd=df[df.Class=='ckd']
normal_count=(len(ckd[ckd.rbc=='normal'].index))
abnormal_count=(len(ckd[ckd.rbc=='abnormal'].index))
ckd['rbc'].value_counts().plot(kind='bar')
#x_pos=np.array('normal','abnormal')
#y_pos=np.array(normal_count, abnormal_count)
print(ckd['bp'].max())
df.to_csv(path_or_buf="E:/DIH/clean_chronic_kidney_disease.csv")