0% found this document useful (0 votes)
14 views

Pandasbasics - Ipynb - Colaboratory (Day3)

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Pandasbasics - Ipynb - Colaboratory (Day3)

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

5/12/2021 Pandasbasics(day3).

ipynb - Colaboratory

pip install pandas

import pandas as pd
heartdata=pd.read_csv("/content/Dataset.csv")
print(heartdata)

type(heartdata)

heartdata.shape

(1190, 12)

heartdata.info()

heartdata.head()

heartdata.columns

heartdata

chest fasting max


resting resting exer
age sex pain cholesterol blood heart
bp s ecg ang
type sugar rate

0 40 1 2 140 289 0 0 172

1 49 0 3 160 180 0 0 156

2 37 1 2 130 283 0 1 98

3 48 0 4 138 214 0 0 108

4 54 1 3 150 195 0 0 122

... ... ... ... ... ... ... ... ...

1185 45 1 1 110 264 0 0 132

1186 68 1 4 144 193 1 0 141

1187 57 1 4 130 131 0 0 115

1188 57 0 2 130 236 0 2 174

1189 38 1 3 138 175 0 0 173

# sort the dataset in ascending order of age


heartdata.sort_values('age')

# sort the dataset in descending order of age


heartdata.sort_values('age',ascending=False)
https://colab.research.google.com/drive/1A699lGpJALnxi0hbrcd2eRffGRZCdwBk#scrollTo=nK8gakKahAEz&printMode=true 1/3
5/12/2021 Pandasbasics(day3).ipynb - Colaboratory

#display the sex column only


heartdata['sex']

heartdata['target']

#display the target values of first 10 records


heartdata[0:10]['target']

#display the sex and target columns


heartdata[['sex','target']]

#display sex and target of records from 100 to 200 positions


heartdata[100:201][['sex','target']]

heartdata.describe()

#display the maximum value of cholesterol


heartdata['cholesterol'].max()

603

#dispaly the row number of max cholesterol record


heartdata['cholesterol'].idxmax()

149

heartdata.iloc[149]['cholesterol']

# find the number of people suffereing from heartdisease and not suffering from heart dise
heartdata['target'].value_counts()

#find number of males and females


heartdata['sex'].value_counts()

1 909
0 281
Name: sex, dtype: int64

#display the records of males suffering from heartdisease


heartdata[(heartdata['sex']==1) & (heartdata['target']==1)]

#display the records of males suffering from heartdisease in ascending order of age
x=heartdata[(heartdata['sex']==1) & (heartdata['target']==1)]
print(x)
print(x.sort_values('age'))

https://colab.research.google.com/drive/1A699lGpJALnxi0hbrcd2eRffGRZCdwBk#scrollTo=nK8gakKahAEz&printMode=true 2/3
5/12/2021 Pandasbasics(day3).ipynb - Colaboratory

#No. of females suffering from heartdisease


heartdata[(heartdata['sex']==0) & (heartdata['target']==1)].shape[0]

70

#No. of persons having cholesterol >250 and suffering from heardisease


heartdata[(heartdata['cholesterol']>250) & (heartdata['target']==1)].shape[0]

233

#No. of persons having cholesterol >250 and not suffering from heardisease
heartdata[(heartdata['cholesterol']>250) & (heartdata['target']==0)].shape[0]

193

#No. of females having cholesterol >250 and suffering from heardisease


heartdata[(heartdata['sex']==0) & (heartdata['cholesterol']>250) & (heartdata['target']==1

40

 0s completed at 7:12 PM

https://colab.research.google.com/drive/1A699lGpJALnxi0hbrcd2eRffGRZCdwBk#scrollTo=nK8gakKahAEz&printMode=true 3/3

You might also like