title: How to store values in a Pandas DataFrame as a percentage and not a string
body: <p>I'm using pandas to create data frames which will then be imported into PowerBI for visualization. One of the columns in the data frame is a percentage calculation. </p>
  
  <p>I have no issues calculating the values. However, these values appear without the '%' sign at the end, e.g. 55.2 as opposed to 55.2%.</p>
  
  <p>An example of my initial dataframe:</p>
  
  <pre><code>df1 = 
  
  year_per    pass    fail    total
  ---------------------------------
  201901      300     700     1000
  201902      400     600     1000
  201903      200     800     1000
  201904      500     500     1000
  </code></pre>
  
  <p>I then calculate two new columns to state the % of the total that each column represent, such that the new data frame is:</p>
  
  <pre><code>df2 = 
  
  year_per    pass    fail    total    pass%    fail%
  ---------------------------------------------------
  201901      300     700     1000     30.0     70.0
  201902      400     600     1000     40.0     60.0
  201903      200     800     1000     20.0     80.0
  201904      500     500     1000     50.0     50.0
  </code></pre>
  
  <p>These new % columns are created using the following code:</p>
  
  <pre><code>df2['pass%'] = round((df1['pass'] / df1['total']) * 100,1)
  </code></pre>
  
  <p>Which works. PowerBI is happy to use those values. However, I'd like it to display the '%' sign at the end for clarity. Therefore, I updated the calculation code to:</p>
  
  <pre><code>df2['pass%'] = (round((df1['pass'] / df1['total']) * 100,1).astype(str))+'%'
  </code></pre>
  
  <p>This also produces the right output, visually. However, as the values are now strings, PowerBI can't process the new values as the visualization is expecting a number format, not a string.</p>
  
  <p>I've also tried using the following formatting (as mentioned here: <a href="https://stackoverflow.com/questions/5306756/how-to-show-percentage-in-python">how to show Percentage in python</a>):</p>
  
  <pre><code>{0:.1f}%".format()
  </code></pre>
  
  <p>i.e.:</p>
  
  <pre><code>df2['pass%'] = '{0:.1f}%'.format(round((df1['pass'] / df1['total']) * 100,1))
  </code></pre>
  
  <p>but get the error: </p>
  
  <pre><code>'TypeError: unsupported format string passed to Series.__format__'
  </code></pre>
  
  <p>Therefore, I was wondering if there is a way to store the values as a number format with the % sign following the numbers? Otherwise I'll just have to live with the values without the % sign.</p>