Python dataFrame 取指定某一行数据

1、按照索引取值
  
data=pd.DataFrame({
    "company":["A","A","A","A","A","A","A","A","A","A","A","A"],
    "salary":[10,12,13,36,12,10,12,13,36,12,36,12],
    "age":[3,1,1,1,1,2,2,1,3,1,11,4]
}
)
row = data.loc[[0],:]

  


2、找某一列最大值最在行
   
idx = data['age'].argmax()

3、求两列差,并新增一列

data["x1"]=data[["salary","age"]].apply(lambda x:x["salary"]+x["age"],axis=1)
print(data)

  

posted on 2022-09-29 14:53  滚动的蛋  阅读(2375)  评论(0编辑  收藏  举报

导航