这是我第一次使用Python和熊猫(请帮助这个老人)。我有一个带有浮点数和负数的列,我想用条件替换它们。 也就是说,如果数字在-2和-1.6之间,则全部替换为-2等。 如何创建条件(使用if else或other)来修改我的列。多谢了
mean=[]
for row in df.values["mean"]:
if row <= -1.5:
mean.append(-2)
elif row <= -0.5 and =-1.4:
mean.append(-1)
elif row <= 0.5 and =-0.4:
mean.append(0)
else:
mean.append(1)
df = df.assign(mean=mean)
不起作用
创建一个定义条件的函数,然后将其应用于列(我根据自己的想法修复了一些条件):
应用返回相同结果的函数的另一种方法:
你知道吗乐趣.txt地址:
从上面输出:
相关问题 更多 >
编程相关推荐