列处理——列间运算

基于pandas

  • 直接相加
# Adding up all of the fat columns.
# food_info is a dataframe
# Adding two columns will go through and add each value at each position to the corresponding value in the same position.
total_fat = food_info["FA_Sat_(g)"] + food_info["FA_Mono_(g)"] + food_info["FA_Poly_(g)"]
  •  sum函数
column_list = ['Fiber_TD_(g)', 'Sugar_Tot_(g)']
# Let's sum the amount of fiber and sugar in each of the foods.
total = food_info[column_list].sum(axis=1)

 

posted on 2016-01-13 21:57  arsh  阅读(271)  评论(0编辑  收藏  举报

导航