Heart Attacks Analysis
Heart Attacks Analysis
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
In [4]: df = pd.read_excel('data.xlsx')
In [5]: df.head()
Out[5]: age sex cp trestbps chol fbs restecg thalach exang oldpeak slope ca thal target
In [7]: df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 303 entries, 0 to 302
Data columns (total 14 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 age 303 non-null int64
1 sex 303 non-null int64
2 cp 303 non-null int64
3 trestbps 303 non-null int64
4 chol 303 non-null int64
5 fbs 303 non-null int64
6 restecg 303 non-null int64
7 thalach 303 non-null int64
8 exang 303 non-null int64
9 oldpeak 303 non-null float64
10 slope 303 non-null int64
11 ca 303 non-null int64
12 thal 303 non-null int64
13 target 303 non-null int64
dtypes: float64(1), int64(13)
memory usage: 33.3 KB
In [8]: df.isnull().sum()
Out[8]: age 0
sex 0
cp 0
trestbps 0
chol 0
fbs 0
restecg 0
thalach 0
exang 0
oldpeak 0
slope 0
ca 0
thal 0
target 0
dtype: int64
13 target 1 or 0
In [24]: plt.figure(figsize=(12,8))
df["age"].value_counts().plot(kind="bar")
plt.title('Age Distribution')
plt.show()
In [30]: plt.figure(figsize=(12,8))
sns.countplot(x = df['age'], hue = 'target', data=df)
plt.show()
In [32]: plt.figure(figsize=(12,8))
sns.histplot(x = df['age'], hue = 'target', data=df)
plt.show()
In [33]: plt.figure(figsize=(12,8))
sns.countplot(x = df['sex'], hue = 'target', data=df)
plt.show()
#creating subplots
In [43]: df.nunique()
Out[43]: age 41
sex 2
cp 4
trestbps 49
chol 152
fbs 2
restecg 3
thalach 91
exang 2
oldpeak 40
slope 3
ca 5
thal 4
target 2
dtype: int64
In [74]: plt.figure(figsize=(12,8))
sns.heatmap(df.corr(), annot=True)
Out[74]: <AxesSubplot: >
In [78]: plt.figure(figsize=(12,8))
plt.subplot(1,3,1)
sns.boxplot(y=df['age'])
plt.title('Age', fontsize=15)
plt.subplot(1,3,2)
sns.boxplot(y=df['trestbps'])
plt.title('Resting blood pressure', fontsize=15)
plt.subplot(1,3,3)
sns.boxplot(y=df['chol'])
plt.title('Cholestrol level', fontsize=15)
plt.show()