[英]How to find the difference between two columns in a dataframe with either rows in the column have -ve and/or +ve values in Python
I have two columns (x & y) in a df with 4 row scenarios (+ve)-(+ve), (-ve)-(-ve), (+ve)-(-ve) and (-ve)-(+ve).我在 df 中有两列 (x & y),有 4 行场景 (+ve)-(+ve)、(-ve)-(-ve)、(+ve)-(-ve) 和 (-ve) -(+ve)。
df df
x y
3 2
-4 -2
2 -1
-6 1
I want to insert a third column z in the same df and the end result as shown below我想在同一个df中插入第三列z,最终结果如下所示
df df
x y z
3 2 1
-4 -2 -2
2 -1 3
-6 1 -5
Are you looking for this?你在找这个吗?
df['z'] = df['x'] - df['y']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.