吴裕雄--天生自然 PYTHON数据分析:医疗数据分析

吴裕雄--天生自然 PYTHON数据分析:医疗数据分析,第1张

概述import numpy as np # linear algebraimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)# plotlyimport chart_studio.plotly as pyfrom plotly.offline import init_notebook_mode

import numpy as np # linear algebraimport pandas as pd # data processing,CSV file I/O (e.g. pd.read_csv)# plotlyimport chart_studio.plotly as pyfrom plotly.offline import init_notebook_mode,iplotinit_notebook_mode(connected=True)import plotly.graph_obJs as goimport seaborn as sns# word cloud libraryfrom wordcloud import WordCloud# matplotlibimport matplotlib.pyplot as plt# input data files are available in the "../input/" directory.# For example,running this (by clicking run or pressing Shift+Enter) will List the files in the input directory
dataframe = pd.read_csv("F:\kaggleDataSet\healthcare-data\test_2v.csv")
import chart_studio.plotly as pyfrom plotly.graph_obJs import *df_heart_disease = dataframe[dataframe.heart_disease== 1] labels = df_heart_disease.genderpIE1_List=df_heart_disease.heart_diseasedf_hypertension= dataframe[dataframe.hypertension == 1] labels1 = df_hypertension.genderpIE1_List1=df_hypertension.hypertensionlabels2 = dataframe.ResIDence_typepIE1_List2 = dataframe.heart_diseaselabels3 = dataframe.work_typepIE1_List3 = dataframe.heart_diseasefig = {    data: [        {            labels: labels,values: pIE1_List,type: pIE,name: Heart disease,marker: {colors: [rgb(56,75,126),rgb(18,36,37),rgb(34,53,101),rgb(36,55,57),rgb(6,4,4)]},domain: {x: [0,.48],y: [0,.49]},hoverinfo:label+percent+name,textinfo:none        },{            labels: labels1,values: pIE1_List1,marker: {colors: [rgb(177,127,38),rgb(205,152,36),rgb(99,79,rgb(129,180,179),rgb(124,103,37)]},name: Hypertension,domain: {x: [.52,1],textinfo:none        },{            labels: labels2,values: pIE1_List2,marker: {colors: [rgb(33,99),rgb(79,129,102),rgb(151,179,100),rgb(175,49,35),73,147)]},name: ResIDence Type,y: [.51,1]},{            labels: labels3,values: pIE1_List3,marker: {colors: [rgb(146,123,21),rgb(177,34),rgb(206,206,40),51,rgb(35,21)]},name:Work Type,textinfo:none        }            ],layout: {Title: ‘‘,showlegend: False}}iplot(fig)

import chart_studio.plotly as pyimport plotly.graph_obJs as go# Create random data with numpyimport numpy as npdf_250 = dataframe.iloc[:250,:]random_x = df_250.indexrandom_y0 =  df_250.avg_glucose_levelrandom_y1 =  df_250.bmirandom_y2 =  df_250.age# Create tracestrace0 = go.Scatter(    x = random_x,y = random_y0,mode = markers,name = Avg. glucose Level)trace1 = go.Scatter(    x = random_x,y = random_y1,mode = lines+markers,name = BMI)trace2 = go.Scatter(    x = random_x,y = random_y2,mode = lines,name = Age)data = [trace0,trace1,trace2]iplot(data,filename=scatter-mode)

import chart_studio.plotly as pyimport plotly.graph_obJs as godf_heart_disease = dataframe[dataframe.heart_disease==1] labels = df_heart_disease.genderx = labelstrace0 = go.Box(    y=dataframe.age,x=x,name=Age,marker=dict(        color=#3D9970    ))trace1 = go.Box(    y=dataframe.avg_glucose_level,name=Avg. glucose Level,marker=dict(        color=#FF4136    ))trace2 = go.Box(    y=dataframe.bmi,name=BMI,marker=dict(        color=#FF851B    ))data = [trace0,trace2]layout = go.Layout(    yaxis=dict(        Title=Attendants Who Has Heart disease,zeroline=False    ),Boxmode=group)fig = go.figure(data=data,layout=layout)iplot(fig)

import chart_studio.plotly as pyimport plotly.graph_obJs as godf_hypertension= dataframe[dataframe.hypertension == 1] labels1 = df_hypertension.genderx = labels1trace0 = go.Box(    y=dataframe.age,trace2]layout = go.Layout(    yaxis=dict(        Title=Attendants Who Has Hypertension,layout=layout)iplot(fig)

df_heart_disease_1 = dataframe.smoking_status [dataframe.heart_disease == 1  ]        df_hypertension_1  = dataframe.smoking_status [dataframe.hypertension  == 1   ]       trace1 = go.Histogram(    x=df_heart_disease_1,opacity=0.75,name = "Heart disease",marker=dict(color=rgba(171,50,96,0.6)))trace2 = go.Histogram(    x=df_hypertension_1,name = "Hypertension",marker=dict(color=rgba(12,196,0.6)))data = [trace1,trace2]layout = go.Layout(barmode=overlay,Title= Association Between Smoking,Heart disease & Hypertension,xaxis=dict(Title=Smoking Status),yaxis=dict( Title=Attendants),)fig = go.figure(data=data,layout=layout)iplot(fig)

df_heart_disease_1 = dataframe.work_type [dataframe.heart_disease    == 1  ]        df_hypertension_1 = dataframe.work_type [dataframe.hypertension    == 1   ]     trace1 = go.Histogram(    x=df_heart_disease_1,0.6)))data = [trace1,Title= Association Between Work Type,xaxis=dict(Title=‘‘),layout=layout)iplot(fig)

总结

以上是内存溢出为你收集整理的吴裕雄--天生自然 PYTHON数据分析:医疗数据分析全部内容,希望文章能够帮你解决吴裕雄--天生自然 PYTHON数据分析:医疗数据分析所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1195634.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存