title: pandas: Keep only top n values and set others to 0
body: <p>In a pandas dataframe, for every row, I want to keep only the top N values and set everything else to 0.
  I can iterate through the rows and do it but I am sure python/pandas can do it elegantly in a single line.  </p>
  
  <p>For e.g.: for N = 2 </p>
  
  <pre><code>Input:
  A   B   C   D
  4   10  10  6
  5   20  50  90
  6   30  6   4
  7   40  12  9
  
  Output:
  A   B   C   D
  0   10  10  0
  0   0   50  90
  6   30  6   0
  0   40  12  0
  </code></pre>