#2.1.4 Data Manipulation with pandas.md

1.標(biāo)準(zhǔn)化:列/最大值

While there are many ways to normalize data, one of the simplest ways is to divide all of the values in a column by that column's maximum value. This way, all of the columns will range from 0 to 1. To calculate the maximum value of a column, we use the Series.max()
method.

input
max_protein = food_info["Protein_(g)"].max()
normalized_protein = food_info["Protein_(g)"] / max_protein
print(normalized_protein.head(5))

output

0 0.009624 
1 0.009624 
2 0.003170 
3 0.242301 
4 0.263134 
Name: Protein_(g), dtype: float64

2.列之間的加減

food_info["Normalized_Protein"] = food_info["Protein_(g)"] / food_info["Protein_(g)"].max()
food_info["Normalized_Fat"] = food_info["Lipid_Tot_(g)"] / food_info["Lipid_Tot_(g)"].max()
food_info["Norm_Nutr_Index"] = 2*food_info["Normalized_Protein"]  + (-0.75*food_info["Normalized_Fat"])

3.創(chuàng)建一個(gè)新列

food_info["Normalized_Protein"] = normalized_protein
food_info["Normalized_Fat"] = normalized_fat

4.升降序排列文檔:Dataframe.sort_values(‘YY’, ascending=True)

food_info.sort_values("Norm_Nutr_Index", inplace=True, ascending=False)
  • inplace=True,不創(chuàng)建新的對(duì)象,直接在原始對(duì)象上盡心修改;
  • inplace=False,在對(duì)原始對(duì)象進(jìn)行修改,而會(huì)創(chuàng)建新的對(duì)象;
  • ascending:
    Sort ascending vs. descending. Specify list for multiple sort orders. If this is a list of bools, must match the length of the by.
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 11,173評(píng)論 0 23
  • 過來人會(huì)說 有個(gè)懂你的人挺好 被愛的幸福 不是那些沒有辛苦愛過別人的人能體會(huì) 被愛,在用尊重,感恩的真心回應(yīng)后 就...
    那個(gè)在看大象洗澡的人閱讀 251評(píng)論 0 0
  • 我喜歡溫柔的人 喜歡朝夕相處默契 喜歡相互尊重的獨(dú)立 喜歡一言不發(fā)又相見甚歡 喜歡突如其來的問候 不做作省略了假意...
    仰望星空yiy閱讀 161評(píng)論 0 0
  • 文/斷劍裂冰 咳咳,怎么突然覺得這個(gè)話題有點(diǎn)嚴(yán)肅了?!放松,放松,今天我們只聊游戲,不談人生。 既然談到游戲,想到...
    筱斷閱讀 652評(píng)論 4 3
  • 第六課 寫作:寫北京 上一節(jié)課同學(xué)們仿寫得不亦樂乎,但其中還包含了一些問題。我們這節(jié)課除了解決一下每位同學(xué)各自在仿...
    田源ty閱讀 505評(píng)論 0 1

友情鏈接更多精彩內(nèi)容