<jupyter_start><jupyter_text>**Exploratory Data Analysis**This EDA will analysis will explore the dataset provided whilst attempting to answer the research questions.  **Importing Packages**<jupyter_code>## This notebook will be used to analyze data from the new_heart_file.csv

import pandas as pd
import numpy as np
import seaborn as sns
import os 
from pandas_profiling import ProfileReport
import matplotlib.pyplot as plt
#from .. import project_functions - invalid syntax

%matplotlib inline<jupyter_output><empty_output><jupyter_text>**Research Questions** 1. Are women more likely than men to have a heart attack?2. Do higher cholesterol levels increase the chances of a heart attack occuring?3. What variable relationships result in a heart attack?  **Loading the Dataframe**<jupyter_code>df = pd.read_csv('new_heart_file.csv')

df.head()
df.shape
# 303 rows and 10 columns<jupyter_output><empty_output><jupyter_text>Rows = 303 Columns = 14<jupyter_code>df.columns
df.nunique()
df.describe().apply(lambda s: s.apply(lambda x: format(x, 'f')))

# The removed column "Unnamed: 0" is still present in the dataframe
#need to get rid of it 

df["Chest Pain"]
# set numeric data
df.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 303 entries, 0 to 302
Data columns (total 10 columns):
 #   Column               Non-Null Count  Dtype
---  ------               --------------  -----
 0   Unnamed: 0           303 non-null    int64
 1   Age                  303 non-null    int64
 2   Sex                  303 non-null    int64
 3   Chest Pain           303 non-null    int64
 4   Resting bp(mmHg)     303 non-null    int64
 5   Cholesterol          303 non-null    int64
 6   Fasting Blood Sugar  303 non-null    int64
 7   Resting ECG          303 non-null    int64
 8   Max Heart Rate       303 non-null    int64
 9   Result               303 non-null    int64
dtypes: int64(10)
memory usage: 23.8 KB<jupyter_text>**Cleaning and Grouping Data**<jupyter_code>df.groupby(by='Age')
df.agg([np.mean])<jupyter_output><empty_output><jupyter_text>The **mean** age of patients is 54.<jupyter_code>df['Result']= df['Result'].map({1:'yes', 0:'no'})
df['Chest Pain'] = df['Chest Pain'].map({0:'Non-Anginal Pain',2:'Typical Angina'})<jupyter_output><empty_output><jupyter_text>Changed the outputs from in columns Result and Chest Pain in order for the reader to more clearly understand the information.**Typical Angina**: Sub-sternal chest pain caused by physical exertion or emotional stress<jupyter_code>df.groupby(by='Sex').size()
#this separates out the men and the women.
# 0 = female
# 1 = male<jupyter_output><empty_output><jupyter_text>Sex of patients is separated into female and male Female = 0 Male = 1<jupyter_code>quotient = 207 / 302
percent = quotient*100
print(percent)<jupyter_output>68.54304635761589<jupyter_text>There are **302** patients in this study, 96 are women and 207 are men. This means that **68.543%** of patients are men. For obvious reasons we can assume that there will be a higher number of male patients experiencing a heart attack than female patients.<jupyter_code>df.head()<jupyter_output><empty_output><jupyter_text>**Data Visualizations**<jupyter_code>ax = sns.histplot (data = df, x="Sex",stat="count", palette="magma")
ax.set_title ("Count of Heart Attack Per Sex")
# Figure showing that there were obviously more men in this study<jupyter_output><empty_output><jupyter_text>Figure 1. Displays the number of heart attacks occuring between male and female patients. With heart attacks resulting more frequently in male patients at **>100**.<jupyter_code>plt.figure(figsize=(20,30))
plt.subplots_adjust(left=0.1,
                    bottom=0.1, 
                    right=0.9, 
                    top=0.9, 
                    wspace=0.4, 
                    hspace=0.4)

plt.subplot(4,2,1)
plt.title('Occurence of Heart Attacks Per Sex',fontsize=15)
sns.countplot(data = df, x='Result', hue= 'Sex', palette = 'magma')<jupyter_output><empty_output><jupyter_text>Figure 2. Countplot displaying the prevalence of heart attack results for the sexes.<jupyter_code>plt.figure(figsize=(20,30))
plt.subplots_adjust(left=0.1,
                    bottom=0.1, 
                    right=0.9, 
                    top=0.9, 
                    wspace=0.4, 
                    hspace=0.4)

plt.subplot(4,2,1)
plt.title(' Chest Pain by Sex',fontsize=15)
sns.countplot(data= df, x="Chest Pain", hue='Sex', palette= "magma")<jupyter_output><empty_output><jupyter_text>Figure 3. Countplot exhibiting the type of chest pain felt by the patients. Male patients experienced more of typical angina<jupyter_code>plt.figure(figsize=(20,30))
plt.subplots_adjust(left=0.1,
                    bottom=0.1, 
                    right=0.9, 
                    top=0.9, 
                    wspace=0.4, 
                    hspace=0.4)

plt.subplot(4,2,1)
plt.title(' Fasting Blood Sugar by Sex',fontsize=15)
sns.countplot(data= df, x="Fasting Blood Sugar", hue='Sex', palette= "magma")<jupyter_output><empty_output><jupyter_text>Figure 4. Barplot showing the Fasting Blood Sugar of patients<jupyter_code>a = sns.barplot(data=df,x="Chest Pain", y="Cholesterol", hue="Result",
               palette="magma")
plt.title('The Number of Patients Experiencing Chest Pain vs their Cholesterol')<jupyter_output><empty_output><jupyter_text>Figure 5. Barplot displaying what kind of chest pain was felt by patients along with their cholesterol levels<jupyter_code>df1 = sns.catplot(data=df, x="Result",y="Cholesterol")
plt.title('Result of Heart Attack Due to Cholesterol Level')<jupyter_output><empty_output><jupyter_text>Figure 6. Plot showing the comparison of patient cholesterol levels and whether or not they experienced a heart attack.From this plot it is hard to draw any conclusions about cholesterol and the effect it has on a patient having a heart attack; the values look very similar other than a few outliers.<jupyter_code>sns.displot(df, x = "Cholesterol", hue="Sex", kind="kde", palette="magma")
plt.title('Density of Cholesterol Levels Per Sex')<jupyter_output><empty_output><jupyter_text>Figure 7. Density plot of Cholesterol levels per Sex.<jupyter_code>a = sns.barplot(data=df,x="Sex", y="Cholesterol", hue="Result",
               palette="magma")
plt.title('Cholesterol Level by Sex')<jupyter_output><empty_output><jupyter_text>Figure 8. Barplot showing the cholesterol levels of patients by sex.  **Analyzing Outliers**<jupyter_code>#Effect of Cholesterol on the Result of a Heart Attack
figure = plt.figure(figsize=(20,8))
sns.boxplot(x="Result",y="Cholesterol",data=df, palette="magma")
plt.title('Boxplot for Cholesterol Related to Heart Attack')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1084051084051084, 'fraction_numerical': 0.032224532224532226, 'mean_word_length': 3.9413059427732944, 'pattern_counts': {'":': 0, '<': 68, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '17', 'dir': 'jupyter-structured-clean-dedup', 'id': '656902', 'license': 'MIT', 'n_tokens_mistral': 2348, 'n_tokens_neox': 2078, 'n_words': 640, 'path': 'analysis/Jennifer/Exploratory Data Analysis.ipynb', 'repo_name': 'data301-2021-summer2/project-group49_project', 'size': '6734'}