Pandas: Changing a specific row to percentages
<p>I have a row in a Pandas Data frame that contains the sales rate of my items.</p>

<p>A look at my data:</p>

<pre><code>block_combine
Out[78]: 
END_MONTH         1    2    3   4    5
Total Listings  168  219  185  89  112
Total Sales      85   85   84  41   46
</code></pre>

<p>I can easily calculate the sales % by doing the following:</p>

<pre><code>block_combine.loc["Total Sales Rate"] = block_combine.ix[1,:] / block_combine.ix[0,:]
block_combine

Out[79]: 
END_MONTH                  1           2           3          4           5
Total Listings    168.000000  219.000000  185.000000  89.000000  112.000000
Total Sales        85.000000   85.000000   84.000000  41.000000   46.000000
Total Sales Rate    0.505952    0.388128    0.454054   0.460674    0.410714
</code></pre>

<p>Now what I am attempting to do is to change the "Total Sales Rate" row to <strong>whole number percentages</strong>. I am able to do this if it was a column however I run into issues when I work with rows.</p>

<p>Here is what I attempted:</p>

<pre><code>block_combine.loc["Total Sales Rate"] = pd.Series(["{0:.0f}%".format(val * 100) for val in block_combine.loc["Total Sales Rate"]])


block_combine

Out[81]: In [82]: 
END_MONTH           1    2    3    4      5
Total Listings    168  219  185   89  112.0
Total Sales        85   85   84   41   46.0
Total Sales Rate  39%  45%  46%  41%    NaN
</code></pre>

<p>The calculations are off/ shifted to the left. The sales rate given for month 1 is actually the sales rate for month 2 (39%)!</p>