我有一个这样的数据集:ID column_1 column_2 column_3 column 4AAA 0.1 0.6 0.1 0.2AAA 0.2 0.2 0.2 0.1BBB 0.5 0.5 0.1 0.1BBB 0.1 0.3 0.1 0.2output = (df['column_1'] – df['column_2']) / (df['column_3'], 5 * df['column_1'], 0.01 * abs(df['column_4'])).max(axis=1)但它给了我一个错误:SyntaxError: invalid character in identifier预期的输出可以描述为这个例子:对于第一行 - 输出 = (0.1 - 0.6) / max(0.1, 5*0.1, 0.01*abs(0.2)) = -0.5/0.5 = -1 有人可以给我一些提示吗?提前致谢。
2 回答
芜湖不芜
TA贡献1796条经验 获得超7个赞
解决方案是通过连接将它们连接起来,然后按行使用:max
s = pd.concat([df['column_3'],
5 * df['column_1'],
0.01 * abs(df['column_4'])], axis=1).max(axis=1)
output = (df['column_1'] - df['column_2']) / s
print (output)
0 -1.0
1 0.0
2 0.0
3 -0.4
dtype: float64
添加回答
举报
0/150
提交
取消
