title: Possible to round numbers to the hundreds, thousands, etc. using Python 3's number formatting
body: <h1>Specific Issue</h1>
  
  <p>I am trying to print out the numbers on top of the cells in a <code>seaborn</code> heatmap.  For instance, something like:</p>
  
  <pre><code>ax = sns.heatmap(flights, annot=True, fmt=",")
  </code></pre>
  
  <p>(This is taken directly from <a href="https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.heatmap.html#seaborn.heatmap" rel="nofollow noreferrer"><code>seaborn</code>'s documentation</a>, adjusted to be Python 3-friendly.  So if you import <code>seaborn</code>, you can run the same example out of the box.)</p>
  
  <hr>
  
  <p>This generates a fairly respectable figure like the one below:</p>
  
  <p><a href="https://i.stack.imgur.com/3muWk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3muWk.png" alt="heatmap, not quite ideal"></a></p>
  
  <p>However, I would like to see the numbers rounded to the nearest <strong><em>hundreds</em></strong>.  In other words, I want to see numbers like 171 written as 200, and 315 written as 300, etc.</p>
  
  <hr>
  
  <h1>Ideas</h1>
  
  <p>Under the hood, <code>seaborn</code> is really just <code>matplotlib</code>.  I can use <code>matplotlib</code>'s <a href="http://matplotlib.org/users/text_props.html" rel="nofollow noreferrer"><code>text</code> methods</a>.</p>
  
  <p><code>matplotlib</code>'s text relies upon Python 3's <a href="https://docs.python.org/3.1/library/string.html" rel="nofollow noreferrer">text formatting</a>, which has convenient ways to round <strong><em>to the right of the decimal</em></strong>, by doing things like <code>.2</code> to round to the hundred***ths***, but I cannot find anything to round in the other direction.</p>
  
  <hr>
  
  <p>I could simply round the numbers before I push them to the plot, but that will actually alter the plot data itself, which I'd rather avoid.  Therefore, I would like to leaving the <strong><em>underlying numbers that I pass to the plot unaltered</em></strong>, while still being able to print things nicely.</p>
  
  <hr>
  
  <p>As far as I know, the only way to do this is to find a clever way to format things.  Is there a way?</p>
  
  <p>Thanks!</p>
  
  <h1>Update</h1>
  
  <p>I dug further into <a href="https://github.com/mwaskom/seaborn/blob/76655613b5e87e4908f125ebfcc0f77c25772100/seaborn/matrix.py" rel="nofollow noreferrer"><code>seaborn</code>'s code</a>, trying to understand why La Rooy's clever solution below did not work for me.</p>
  
  <p>The relevant line within the <code>seaborn</code> code is:</p>
  
  <pre><code>val = ("{:" + self.fmt + "}").format(val)
  </code></pre>
  
  <hr>
  
  <p>However, for this to work, I would need to be able to alter my <code>pandas</code> dataframe column, which means that I'd need to be able to adjust the column of <code>nd.array</code> elements.</p>
  
  <p>It seems that there is <a href="https://github.com/numpy/numpy/issues/5543" rel="nofollow noreferrer">not yet any underlying <code>.__format__</code> method for a <code>numpy</code> array</a>, but there is an effort to create one.</p>
  
  <p>So, I'm for the moment going to chase this issue no further, and hope that once things sort themselves out, I'll be able to take La Rooy's solution and things should "work".</p>
  
  <p>Once that happens, the solution would be:</p>
  
  <pre><code>&gt;&gt;&gt; class rndarray(np.ndarray):
  ...     def __format__(self, spec):
  ...         return np.ndarray.__format__(int(round(self, -2)), spec)
  ... 
  &gt;&gt;&gt; df['&lt;col_of_interest&gt;'] = map(rndarray, df['&lt;col_of_interest.'])
  </code></pre>
  
  <p>or, if that didn't work, then:</p>
  
  <pre><code>&gt;&gt;&gt; df['&lt;col_of_interest&gt;'].values = map(rndarray, df['&lt;col_of_interest.'].values)
  </code></pre>