批量修改datafram中某一列

如要对df中列名为“values”的值做修改,大于等于50改为1,小于50改为0,可用apply函数来实现:

def fun(x):
    if x >= 50:
        return 1
    else:
        return 0
 
df['values'] = df['values'].apply(lambda x: fun(x))

  

猜你喜欢

转载自www.cnblogs.com/sxinfo/p/11827598.html
今日推荐