Calculating and creating percentage column from two columns
<p>I have a df (<code>Apple_farm</code>) and need to calculate a percentage based off values found in two of the columns (<code>Good_apples</code> and <code>Total_apples</code>) and then add the resulting values to a new column within Apple_farm called 'Perc_Good'.</p>

<p>I have tried:</p>

<pre><code>Apple_farm['Perc_Good'] = (Apple_farm['Good_apples'] / Apple_farm['Total_apples']) *100
</code></pre>

<p>However this results in this error:</p>

<blockquote>
  <p>TypeError: unsupported operand type(s) for /: 'str' and 'str'</p>
</blockquote>

<p>Doing</p>

<p><code>Print Apple_farm['Good_apples']</code>  and <code>Print Apple_farm['Total_apples']</code></p>

<p>Yields a list with numerical values however dividing them seems to result in them being converted to strings?</p>

<p>I have also tried to define a new function:</p>

<pre><code>def percentage(amount, total):
    percent = amount/total*100
    return percent
</code></pre>

<p>but are unsure on how to use this.</p>

<p>Any help would be appreciated as I am fairly new to Python and pandas!</p>