Pandas DataFrame: Compute values based on column min/max
<p>I have an NxN DataFrame with values I need to scale to a range of values that signify importance, where 0 is irrelevant and 3 is very important.</p>

<p>The formula I'm using to scale of course depends on the min and max values in each column, which are different for each column: Col A's range could be 1-12 while Col B's range could be 1M to 45M.</p>

<p>Here's the formula I'm using.</p>

<p><code>min_importance + ((max_importance - min_importance) / (max_spec_value - min_spec_value)) * (spec_value - min_spec_value)</code></p>

<p>How do I create a new DataFrame or dictionary with scaled values for each column, while retaining the index, which is needed later for identification?</p>

<p>I tried creating a function with the above formula, and using apply() to call the function for each row, but I can't pass column min/max to the function, so that doesn't work.</p>

<p>DataFrame sample ("Body: retail price" and "Body: sensor resolution" are columns):</p>

<pre>                       Body: retail price  Body: sensor resolution  
Body name                                                            
Nikon D500                        2000.00                 20668416   
Nikon D7000                       1200.00                 16084992   
Sony Alpha 7R II                  3199.00                 42177408   
Canon EOS 5D Mark III             3499.00                 22118400   
Canon 7D Mark II                  1799.00                 19961856   
iPhone 6 (front)                   699.00                  1000000   
iPhone 6 (rear)                    699.00                  7990272   
Fujifilm X-T1                     1299.95                 15980544   
Fujifilm X-T2                     1599.00                 24000000</pre>