title: How do I custom format a pandas integer column to display with commas as thousands separators?
body: <p>I've got a dataframe column <code>GDP/year</code> from a dataset about suicides over some years. The data type of this column is currently object (string), but I want it as integer. </p>
  
  <p>The values are commas separated so I can't directly transform them to integers. I tried string-removing the commas, storing as integer, then I  introduce the commas again, but its the type reverts back to object.</p>
  
  <p>The dataset: <a href="https://www.kaggle.com/russellyates88/suicide-rates-overview-1985-to-2016" rel="nofollow noreferrer">https://www.kaggle.com/russellyates88/suicide-rates-overview-1985-to-2016</a> </p>
  
  <pre><code># convert to int...
  suicides[' gdp_for_year ($) '] = suicides[' gdp_for_year ($) '].str.replace(',','').astype(int) 
  # now reformat with commas as thousands separator...
  suicides[' gdp_for_year ($) '] = suicides[' gdp_for_year ($) '].astype(int).apply(lambda x: "{:,}".format(x)) 
  # ...wanted to get dtype integer, but it's back to object
  </code></pre>