# Heart Attack Analysis and Visualization Using Python

Here we analyze the Heart Attack rate, at which age Heart Attack is high and low risk

Step:-1

First, we import the necessary libraries after that, we import the dataset

```import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
import os
import plotly.express as px```
```HEART_ATTACK = pd.read_csv("HEART_ATTACK.csv")
HEART_ATTACK.shape
HEART_ATTACK```
`print(list(HEART_ATTACK.columns))`

Step:-2

Now we see the output

`HEART_ATTACK['output'].value_counts()`

Here male denoted as 1 and female denoted as 0

```sns.set_theme(context="notebook",style="dark",font_scale=1)
plt.style.use("seaborn")

plt.figure(figsize=(10,5))
c=sns.countplot(data=HEART_ATTACK,x='output',palette='Set2')
plt.show()```

Now we see the male rate is higher than female

Step:-3

head(): This helps to see a few sample rows of the data

```HEART_ATTACK.head()
```

corr(): This helps to find the pairwise correlation of all columns in the data frame

`HEART_ATTACK.corr()`

Now we plot the heat map

```plt.figure(figsize=(40,20))
sns.heatmap(HEART_ATTACK.corr(),annot=True)```

After plotting the heat map we plot pair plot

```HEART_ATTACK.sex.value_counts()
```

Step:-4

Now we count how many are male and female effect by Heart Attack

`HEART_ATTACK.sex.value_counts()`

Now we plot Heart Attack Frequency for sex

```pd.crosstab(HEART_ATTACK.age, HEART_ATTACK.sex).plot(kind="bar", figsize=(10,6), color=["salmon", "lightblue"])
plt.xlabel("age")
plt.ylabel("amount")
plt.legend(["male", "female"])
plt.xticks(rotation=90);```
```S=HEART_ATTACK["sex"].value_counts().reset_index()
px.pie(S,names="index",values="sex")```

here we see male are 68.3% and female are 31.7% effect by Heart Attack

Step:-5

Now we see the type of chest pain with the number of patients

```Chest_pain=HEART_ATTACK["cp"].value_counts().reset_index()
Chest_pain```
```plt.figure(figsize=(20,5))
sns.barplot(x=Chest_pain["index"],y=Chest_pain["cp"])
plt.xlabel("type")
plt.ylabel("digit")
plt.show()
```

Step:-6

At which age Heart Attack is high and low risk

```v=pd.crosstab(HEART_ATTACK["age"],HEART_ATTACK["output"]).reset_index()
v.columns=["age","low_risk","high_risk"]
v```

Now we plot at which age high and low risk

`px.bar(v,v["age"],v["low_risk"],title="RISK OF LOW HEART-ATTACK WITH AGE")`
`px.bar(v,v["age"],v["high_risk"],title="RISK OF HIGH HEART-ATTACK WITH AGE")`

Step:-

Here we plot the blood pressure  with age

```plt.figure(figsize=(20,10))
sns.barplot(y="trtbps",x="age",data=HEART_ATTACK)
plt.title("BLOOD PRESSURE WITH AGE")
plt.xlabel("age")
plt.ylabel("B.P")
plt.show()
```

Here we plot the cholesterol with age

```plt.figure(figsize=(20,10))
sns.barplot(y="chol",x="age",data=HEART_ATTACK)
plt.title("CHOLESTROL LEVEL  WITH AGE")
plt.xlabel("age")
plt.ylabel("C L")
plt.show()```

Here we plot the Heart rate with age

```plt.figure(figsize=(20,10))
sns.barplot(y="thalachh",x="age",data=HEART_ATTACK)
plt.title("HEART RATE  WITH AGE",fontsize=20)
plt.xlabel("age")
plt.ylabel("rate")
plt.show()
```