Categories
pandas python

How to calculate percentage with Pandas’ DataFrame

How to add another column to Pandas’ DataFrame with percentage? The dict can change on size.

>>> import pandas as pd
>>> a = {'Test 1': 4, 'Test 2': 1, 'Test 3': 1, 'Test 4': 9}
>>> p = pd.DataFrame(a.items())
>>> p
0 1
0 Test 2 1
1 Test 3 1
2 Test 1 4
3 Test 4 9
[4 rows x 2 columns]