pandas: how to get the percentage for each row
<p>When I use pandas <code>value_count</code> method, I get the data below:</p>

<pre><code>new_df['mark'].value_counts()

1   1349110
2   1606640
3   175629
4   790062
5   330978
</code></pre>

<p>How can I get the percentage for each row like this?</p>

<pre><code>1   1349110 31.7%
2   1606640 37.8%
3   175629  4.1%
4   790062  18.6%
5   330978  7.8%
</code></pre>

<p>I need to divide each row by the sum of these data.</p>

<p>I think you need:</p>

<pre><code>#if output is Series, convert it to DataFrame
df = df.rename('a').to_frame()

df['per'] = (df.a * 100 / df.a.sum()).round(1).astype(str) + '%'

print (df)
         a    per
1  1349110  31.7%
2  1606640  37.8%
3   175629   4.1%
4   790062  18.6%
5   330978   7.8%
</code></pre>

<p><strong>Timings</strong>:</p>

<p>It seems faster is use <code>sum</code> as twice <code>value_counts</code>:</p>

<pre><code>In [184]: %timeit (jez(s))
10 loops, best of 3: 38.9 ms per loop

In [185]: %timeit (pir(s))
10 loops, best of 3: 76 ms per loop
</code></pre>

<p>Code for timings:</p>

<pre><code>np.random.seed([3,1415])
s = pd.Series(np.random.choice(list('ABCDEFGHIJ'), 1000, p=np.arange(1, 11) / 55.))
s = pd.concat([s]*1000)#.reset_index(drop=True)

def jez(s):
    df = s.value_counts()
    df = df.rename('a').to_frame()
    df['per'] = (df.a * 100 / df.a.sum()).round(1).astype(str) + '%'
    return df

def pir(s):
    return pd.DataFrame({'a':s.value_counts(), 
                         'per':s.value_counts(normalize=True).mul(100).round(1).astype(str) + '%'})

print (jez(s))
print (pir(s))
</code></pre>

python pandas sum percentage series