以下代碼是基于python3.5.0編寫的
創(chuàng)新互聯(lián)專注于宜興企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè),商城系統(tǒng)網(wǎng)站開發(fā)。宜興網(wǎng)站建設(shè)公司,為宜興等地區(qū)提供建站服務(wù)。全流程定制網(wǎng)站設(shè)計,專業(yè)設(shè)計,全程項目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)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 #----------------------------數(shù)據(jù)歸一化----------------------------------- 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)"])
網(wǎng)站名稱:pandas數(shù)值計算與排序方法-創(chuàng)新互聯(lián)
分享鏈接:http://jinyejixie.com/article38/jejsp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、域名注冊、全網(wǎng)營銷推廣、小程序開發(fā)、用戶體驗、網(wǎng)站營銷
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容