以下代码是基于python3.5.0编写的
创新互联专注于宜兴企业网站建设,成都响应式网站建设,商城系统网站开发。宜兴网站建设公司,为宜兴等地区提供建站服务。全流程定制网站设计,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务import pandas food_info = pandas.read_csv("food_info.csv") # ---------------------特定列加减乘除------------------------- print(food_info["Iron_(mg)"]) div_1000 = food_info["Iron_(mg)"] / 1000 add_100 = food_info["Iron_(mg)"] + 100 sub_100 = food_info["Iron_(mg)"] - 100 mult_2 = food_info["Iron_(mg)"]*2 # ---------------------某两列相乘--------------------------- water_energy = food_info["Water_(g)"] * food_info["Energ_Kcal"] # ----------------------把某一列除1000,再添加新列---------------------------- iron_grams = food_info["Iron_(mg)"] / 1000 food_info["Iron_(g)"] = iron_grams #-------------------Score=2×(Protein_(g))−0.75×(Lipid_Tot_(g))-------------- weighted_protein = food_info["Protein_(g)"] * 2 weighted_fat = -0.75 * food_info["Lipid_Tot_(g)"] initial_rating = weighted_protein + weighted_fat #----------------------------数据归一化----------------------------------- max_calories = food_info["Energ_Kcal"].max() #找列大值 normalized_calories = food_info["Energ_Kcal"] / max_calories normalized_protein = food_info["Protein_(g)"] / food_info["Protein_(g)"].max() normalized_fat = food_info["Lipid_Tot_(g)"] / food_info["Lipid_Tot_(g)"].max() food_info["Normalized_Protein"] = normalized_protein food_info["Normalized_Fat"] = normalized_fat # -------------------------------排序---------------------------------- food_info.sort_values("Sodium_(mg)", inplace=True) #升序,inplace=True表示不从建DataFrame print(food_info["Sodium_(mg)"]) food_info.sort_values("Sodium_(mg)", inplace=True, ascending=False) #降序,ascending=False表示降序 print(food_info["Sodium_(mg)"])
网站名称:pandas数值计算与排序方法-创新互联
分享链接:https://www.cdcxhl.com/article38/jejsp.html
成都网站建设公司_创新互联,为您提供定制开发、域名注册、全网营销推广、小程序开发、用户体验、网站营销
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联