title: How to do sort, calculation and find the maximum in python
body: <p>recently I want to do some sorting, calculation and find the maximum in data frame.
  For example:</p>
  <pre><code>data = {'Name':['Penny','Ben','Benny','Mark'], 
          'Eng':[5,1,4,3], 
          'Math':[1,5,3,2],
          'Physics':[2,5,3,1],
          'Sports':[4,5,2,3],
          'Total':[12,16,12,9]}
   
  df1=pd.DataFrame(data, columns=['Name','Eng','Math','Physics','Sports','Total']) 
  df1
  </code></pre>
  <p><a href="https://i.stack.imgur.com/EsTaj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EsTaj.png" alt="enter image description here" /></a></p>
  <p>I want to get the range of different subject and I find a function</p>
  <pre><code>numpy.ptp
  </code></pre>
  <p>Which can find the range of values (maximum - minimum) along an axis,
  thus I do this
  import numpy as np</p>
  <pre><code>cols_of_interest = ['Eng','Math','Sports','Physics']
  np.ptp(df1[cols_of_interest].values, axis=1)
  </code></pre>
  <p>Result</p>
  <pre><code>array([4, 4, 2, 2])
  </code></pre>
  <p>When I get the result, the information from the data frame is lost. For example, I want to find the students who have the largest range
  should be (Penny:4, Ben:4)
  However, when the data size is large, how can I merge those data back to the data frame and find the max?</p>
  <p>Also, for <code>cols_of_interest = ['Eng','Math','Sports','Physics']</code>, when the elements are large (like 100 subjects), is there any elegant way to apply np.ptp?</p>
  <p>Many thanks!!</p>