数学分析项目练习-健康饮食方式如何帮助抵抗新型冠状病毒

为巩固所学的pandas、seaborn、matplotlib等包,作此练习。

根据在kaggle中下载的数据,本文将分析怎么样的饮食习惯能够帮助抵抗新型冠状病毒。
数据来源:kaggle

1.导入模块和数据

# 导入所需模块
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
plt.style.use('ggplot')
# 导入数据
fatsq = pd.read_csv('fatsq.csv')
fsk = pd.read_csv('fsk.csv')
fsqkg = pd.read_csv('fsqkg.csv')
psq = pd.read_csv('psq.csv')
sfd = pd.read_csv('sfd.csv')

2.检查和清洗数据

# 查看数据
fatsq.info()
fatsq.head(20)
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 170 entries, 0 to 169
Data columns (total 32 columns):
Country                         170 non-null object
Alcoholic Beverages             170 non-null float64
Animal Products                 170 non-null float64
Animal fats                     170 non-null float64
Aquatic Products, Other         170 non-null float64
Cereals - Excluding Beer        170 non-null float64
Eggs                            170 non-null float64
Fish, Seafood                   170 non-null float64
Fruits - Excluding Wine         170 non-null float64
Meat                            170 non-null float64
Miscellaneous                   170 non-null float64
Milk - Excluding Butter         170 non-null float64
Offals                          170 non-null float64
Oilcrops                        170 non-null float64
Pulses                          170 non-null float64
Spices                          170 non-null float64
Starchy Roots                   170 non-null float64
Stimulants                      170 non-null float64
Sugar Crops                     170 non-null float64
Sugar & Sweeteners              170 non-null float64
Treenuts                        170 non-null float64
Vegetal Products                170 non-null float64
Vegetable Oils                  170 non-null float64
Vegetables                      170 non-null float64
Obesity                         167 non-null float64
Undernourished                  163 non-null object
Confirmed                       161 non-null float64
Deaths                          161 non-null float64
Recovered                       161 non-null float64
Active                          161 non-null float64
Population                      170 non-null float64
Unit (all except Population)    170 non-null object
dtypes: float64(29), object(3)
memory usage: 42.6+ KB
#fatsq
fatsq = fatsq.dropna(axis=0)
fatsq.Undernourished = fatsq.Undernourished.str.replace("<2.5","2")
fatsq.Undernourished = pd.to_numeric(fatsq.Undernourished,errors='coerce')
#fsk
fsk = fsk.dropna(axis=0)
fsk.Undernourished = fsk.Undernourished.str.replace("<2.5","2")
fsk.Undernourished = pd.to_numeric(fsk.Undernourished,errors='coerce')
#fsqkg
fsqkg = fsqkg.dropna(axis=0)
fsqkg.Undernourished = fsqkg.Undernourished.str.replace("<2.5","2")
fsqkg.Undernourished = pd.to_numeric(fsqkg.Undernourished,errors='coerce')
#psq
psq = psq.dropna(axis=0)
psq.Undernourished = psq.Undernourished.str.replace("<2.5","2")
psq.Undernourished = pd.to_numeric(psq.Undernourished,errors='coerce')
  • 对于含空值的数据,若赋值为0,会对结果影响较大,故全部删去所在行
  • 而Undernourished列的值应该都是数字,查看后发现异常值都是’<2.5’,故全改成’2’,并转换成float类型
  • 后三个文件经观察是相同的问题,故作相同操作
  • 操作检查后,数据已不存在其他问题

3.根据所知数据,首先探究肥胖、营养不良和新型冠状病毒的患病率、死亡率、治愈率的关系

# 图一 肥胖和确诊率
sns.lmplot('Obesity','Confirmed',data=fatsq)
plt.show()

在这里插入图片描述

由图可知,肥胖率高的国家,确诊率也高很多,而肥胖率低的国家,确诊率普遍很低,没有高的情况出现。

# 图二 肥胖和死亡率
sns.lmplot('Obesity','Deaths',data=fatsq)
plt.show()

在这里插入图片描述

由图可知,高死亡率出现在高肥胖率的国家

# 图三 营养不良和确诊率
sns.lmplot('Undernourished','Confirmed',data=fatsq)
plt.show()

在这里插入图片描述

# 图四 营养不良和死亡率
sns.lmplot('Undernourished','Deaths',data=fatsq)
plt.show()

在这里插入图片描述

  • 而营养相对不足与国家确诊率和死亡率程负相关,与常识不符。分析原因可能是,这些国家富有,所以流动性高肥胖率高,故而可分析肥胖率和营养不良率之间的关系
sns.lmplot('Obesity','Undernourished',fatsq)
plt.show()

在这里插入图片描述

  • 有图可见一般肥胖率高的国家,营养不良率就低,而营养不良率相对高的国家,肥胖率很低

由此可见,肥胖率对新型冠状病毒的影响较大,且成正相关,而营养不良的影响较低

y = [i for i in range(1,24)]
s1 = list(map(lambda x:fsqkg.iloc[:,x].corr(fsqkg.iloc[:,24]),y))  #求出每种食物脂肪摄取量与肥胖率的相关性系数
s2 = list(map(lambda x:fsqkg.iloc[:,x].corr(fsqkg.iloc[:,26]),y))  #求出每种食物脂肪摄取量与确诊率的相关性系数
s3 = list(map(lambda x:psq.iloc[:,x].corr(fsqkg.iloc[:,26]),y))    #求出每种食物蛋白质与确诊率的相关性系数
df1 = pd.DataFrame(s1,index=fsqkg.columns[1:24],columns=fsqkg.columns[24:25])
df2 = pd.DataFrame(s2,index=fsqkg.columns[1:24],columns=fsqkg.columns[26:27])
df3 = pd.DataFrame(s3,index=fsqkg.columns[1:24],columns=fsqkg.columns[26:27])
df1 = df1.sort_values('Obesity')
df2 = df2.sort_values('Confirmed')
df3 = df3.sort_values('Confirmed')
df1.plot.bar(figsize=(15,8))
plt.show()

在这里插入图片描述由每种食物脂肪摄取量与肥胖率的相关性系数作图如上

df2.plot.bar(figsize=(15,8))
plt.show()

在这里插入图片描述由每种食物脂肪摄取量与确诊率的相关性系数作图如上

df3.plot.bar(figsize=(15,8))
plt.show()

在这里插入图片描述

由每种食物蛋白质摄取量与肥胖率的相关性系数作图如上
#筛选出相关性高的食物类型
df11 = df1.query('Obesity>0.4')
df22 = df2.query('Confirmed>0.2')
df33 = df3.query('Confirmed<-0.2')
#和食物类型解释表相结合,得出和肥胖确诊率相关性的食物
cf = df11.join(df22,how='inner')
eat_no = cf.merge(sfd,left_on=cf.index,right_on=sfd.Categories)
eat_no
key_0ObesityConfirmedCategoriesItems
0Animal fats0.4083940.401826Animal fatsButter, Ghee; Cream; Fats, Animals, Raw; Fish,...
1Eggs0.4573530.325090EggsEggs
2Milk - Excluding Butter0.4987070.372638Milk - Excluding ButterMilk - Excluding Butter
3Meat0.5682450.327027MeatBovine Meat; Meat, Other; Mutton & Goat Meat; ...
4Animal Products0.5787880.463564Animal ProductsAquatic Animals, Others; Aquatic Plants; Bovin...

上表为与确诊率和肥胖率相关性高得食物,平时最好减少摄取量

eat_yes = df33.merge(sfd,left_on=df33.index,right_on=sfd.Categories)
eat_yes
key_0ConfirmedCategoriesItems
0Treenuts-0.515067TreenutsNuts and products
1Cereals - Excluding Beer-0.442146Cereals - Excluding BeerBarley and products; Cereals, Other; Maize and...
2Oilcrops-0.282788OilcropsCoconuts - Incl Copra; Cottonseed; Groundnuts ...
3Offals-0.277227OffalsOffals, Edible

上表为与确诊率和肥胖率负相关性高得食物,我们可以多从这些食物中摄取所需的营养物


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值