0


【分析BMI指数~python】

目录~python


个人昵称:lxw-pro
个人主页:欢迎关注 我的主页
个人感悟: “失败乃成功之母”,这是不变的道理,在失败中总结,在失败中成长,才能成为IT界的一代宗师。

分析班级BMI指数

n = int(input("请您输入您想测算的人数(用数字表示):"))
for i in range(n):
    classBmi = input("请输入姓名、身高和体重(中间以空格隔开):").split(' ')
    name = classBmi[0]
    height = eval(classBmi[1])
    weight = eval(classBmi[2])

    bmi = weight / pow(height, 2)
    print("BMI数值为:{:.2f}".format(bmi))
    who, nat = "", ""

    if bmi < 18.5:
        who, nat = "偏瘦", "偏瘦"
    elif 18.5 <= bmi < 24:
        who, nat = "正常", "正常"
    elif 24 <= bmi < 25:
        who, nat = "正常", "偏胖"
    elif 25 <= bmi < 28:
        who, nat = "偏胖", "偏胖"
    elif 28 <= bmi < 30:
        who, nat = "偏胖", "偏胖"
    else:
        who, nat = "肥胖", "肥胖"
    print('{0}的BMI数值为{1}, BMI指标为:国际"{2}", 国内"{3}"'.format(name, format(bmi, '.2f'), who, nat))

运行效果如下:

在这里插入图片描述


分析年级BMI指数

gradeBmis = [[('20级大数据一班', "王平", 1.66, 55), ('20级大数据一班', '王恰', 1.65, 52), ('20级大数据一班', '周馓', 1.75, 66)],
             [('20级大数据二班', "仁济", 1.66, 64), ('20级大数据二班', '范德萨', 1.72, 66), ('20级大数据二班', '陈琳', 1.76, 56)]]

for classes in gradeBmis:
    print("\n---------------班级分割线----------------")
    for person in classes:
        className, name, height, weight = person[0], person[1], person[2], person[3]
        who, nat = "", ""
        bmi = weight / pow(height, 2)

        if bmi < 18.5:
            who, nat = "偏瘦", "偏瘦"
        elif 18.5 <= bmi < 24:
            who, nat = "正常", "正常"
        elif 24 <= bmi < 25:
            who, nat = "正常", "偏胖"
        elif 25 <= bmi < 28:
            who, nat = "偏胖", "偏胖"
        elif 28 <= bmi < 30:
            who, nat = "偏胖", "偏胖"
        else:
            who, nat = "肥胖", "肥胖"
        print('{0}{1}的BMI数值为{2}, BMI指标为:国际"{3}", 国内"{4}"'.format(className, name, format(bmi, '.2f'), who, nat))

运行效果如下:

在这里插入图片描述

————————————————————————————————————————————

Pandas 每日一练:

# -*- coding = utf-8 -*-# @Time : 2022/7/28 20:34# @Author : lxw_pro# @File : pandas-10 练习.py# @Software : PyCharmimport pandas as pd

lxw = pd.read_excel("site.xlsx")print(lxw)

运行结果为:

     Unnamed:0  Unnamed:0.1   create_dt  ...   yye  sku_cost_prc     lrl
0012016-11-30...8.86.7730.00%1122016-11-30...7.55.7730.00%2232016-11-30...5.03.8530.00%3342016-11-30...19.67.5430.00%4452016-12-02...13.510.3830.00%.......................7517517522016-12-31...1.00.7730.00%7527527532016-12-31...2.01.5430.00%7537537542016-12-31...1.00.7730.00%7547547552016-12-31...7.62.9230.00%7557557562016-12-31...3.32.5430.00%[756 rows x 8 columns]

61、以lxw的列名创建一个dataframe

lm = pd.DataFrame(columns=lxw.columns.to_list())print(lm)

运行结果为:

Empty DataFrame
Columns:[Unnamed:0, Unnamed:0.1, create_dt, sku_cnt, sku_sale_prc, yye, sku_cost_prc, lrl]
Index:[]

62、打印所有利润率不是数字的行

for i inrange(len(lxw)):iftype(lxw.iloc[i,6])!=float:
        lm = lm.append(lxw.loc[i])print(lm)

运行结果为:

    Unnamed:0 Unnamed:0.1   create_dt  ...   yye  sku_cost_prc     lrl
0012016-11-30...8.86.7730.00%1122016-11-30...7.55.7730.00%2232016-11-30...5.03.8530.00%3342016-11-30...19.67.5430.00%4452016-12-02...13.510.3830.00%.......................7517517522016-12-31...1.00.7730.00%7527527532016-12-31...2.01.5430.00%7537537542016-12-31...1.00.7730.00%7547547552016-12-31...7.62.9230.00%7557557562016-12-31...3.32.5430.00%[756 rows x 8 columns]

63、打印所有利润率为30.00%的行

print(lxw[lxw['lrl'].isin(['30.00%'])])

运行结果为:

     Unnamed:0  Unnamed:0.1   create_dt  ...   yye  sku_cost_prc     lrl
0012016-11-30...8.86.7730.00%1122016-11-30...7.55.7730.00%2232016-11-30...5.03.8530.00%3342016-11-30...19.67.5430.00%4452016-12-02...13.510.3830.00%.......................7517517522016-12-31...1.00.7730.00%7527527532016-12-31...2.01.5430.00%7537537542016-12-31...1.00.7730.00%7547547552016-12-31...7.62.9230.00%7557557562016-12-31...3.32.5430.00%[478 rows x 8 columns]

64、重置lxw的行号

lxw = lxw.reset_index()print(lxw)

运行结果为:

     index  Unnamed:0  Unnamed:0.1...   yye  sku_cost_prc     lrl
0001...8.86.7730.00%1112...7.55.7730.00%2223...5.03.8530.00%3334...19.67.5430.00%4445...13.510.3830.00%.......................751751751752...1.00.7730.00%752752752753...2.01.5430.00%753753753754...1.00.7730.00%754754754755...7.62.9230.00%755755755756...3.32.5430.00%[756 rows x 9 columns]

65、删除所有利润率为30.00%的行

l =[]for i inrange(len(lxw)):iftype(lxw.iloc[i,6])!=float:
        l.append(i)

sc = lxw.drop(labels=l, inplace=True)print(sc)# 运行结果为:None

每日一言:

在某一个拥挤的地方,人挤人,你不知道方向在哪里,但如果你站的高一点,看的远一点,就知道周遭的种种拥挤对你来说其实毫无意义!!!


持续更新中…

点赞,你的认可是我创作的

动力


收藏,你的青睐是我努力的

方向


评论,你的意见是我进步的

财富


关注,你的喜欢是我长久的

坚持


在这里插入图片描述

欢迎关注微信公众号【程序人生6】,一起探讨学习哦!!!


本文转载自: https://blog.csdn.net/m0_66318554/article/details/125750544
版权归原作者 lxw-pro 所有, 如有侵权,请联系我们删除。

“【分析BMI指数~python】”的评论:

还没有评论