'how to do count of particular value of given column corresponding to other column

input

output

To count the particular value of given column



Solution 1:[1]

Use pd.crosstab with df.sum:

In [236]: output = pd.crosstab(df['Rel_ID'], df['Values'])
In [238]: output['total'] = output.sum(axis=1)

In [239]: output
Out[239]: 
Values  400.0  500.0  1700.0  6300.0  total
Rel_ID                                     
TESTA       1      1       1       1      4
TESTB       1      0       1       1      3
TESTC       0      1       1       0      2
TESTD       1      0       1       1      3
TESTE       1      1       0       0      2

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mayank Porwal