Pandas: Adding Column With Calculations From Other Columns
I have a csv with measurements: YY-MO-DD HH-MI-SS_SSS | x | y 2015-12-07 20:51:06:608 | 2 | 4 2015-12-07 20:51:07:609 |
Solution 1:
Use np.sqrt
on the result of the squares:
In [10]:
df['z'] = np.sqrt(df['x']**2 + df['y']**2)
df
Out[10]:
x y z
0 2 4 4.472136
1 3 4 5.000000
You can also sum
row-wise the result of np.square
and call np.sqrt
:
In [13]:
df['z'] = np.sqrt(np.square(df[['x','y']]).sum(axis=1))
df
Out[13]:
x y z
0 2 4 4.472136
1 3 4 5.000000
Post a Comment for "Pandas: Adding Column With Calculations From Other Columns"