Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to put every value from the column into the formula? (And make new column with results)

I have a dataframe (df) with columns like this:

Column 1 Column 2 Column 3
-0.01784 90.12232 0.12323
36.50000 1.32003 30.10937
-187.03982 -1.09322 -3.20091

And a formula like this:

y = ((maximum – minimum)**2) + ((x – 10)**2), where

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

maximum = the maximum value in the column

minimum = the minimum value in the column

x = input value from the column (each cell one by one)

y = output value (the result for each cell)

The question is:
How can I put every new value from column into X, receive Y and make it for each column?
The result should be like:

Column 1 Column 2 Column 3
50070.40824 14739.86089 1207.12533
50672.30112 8395.61661 1513.96151
88794.74179 8443.33426 1283.83877

Thanks for the help!!!

>Solution :

You can use:

df.sub(10).pow(2).add(df.max().sub(df.min()).pow(2))

Or:

(df-10)**2 + (df.max()-df.min())**2

Output:

       Column 1      Column 2     Column 3
0  50070.408244  14739.860900  1207.125339
1  50672.301126   8395.616617  1513.961515
2  88794.741791   8443.334267  1283.838779
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading