Fra Fra - 1 year ago 213
Python Question

Norm along row in pandas

I have a pandas Dataframe with N columns representing the coordinates of a vector (for example X, Y, Z, but could be more than 3D).

I would like to aggregate the dataframe along the rows with an arbitrary function that combines the columns, for example the norm:

(X^2 + Y^2 + Y^2)

I want to do something similar to what is done here and here and here but I want to keep it general enough that the number of columns can change and it behaves like

DataFrame.mean(axis = 1)


DataFrame.sum(axis = 1)

Fra Fra
Answer Source

I found a faster solution than what @elyase suggested:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download