I want to count occurrence of a string value in multiple columns in the entire dataframe, for example :
df = pd.DataFrame({'type1':['A11','B11','A11','A'],
'type2':['A12','C','A12','D11'],
'type3':['C','D11','B','D12'],
'type4':[np.nan,'E12','C','E']
})
df
type1 type2 type3 type4
0 A11 A12 C NaN
1 B11 C D11 E12
2 A11 A12 B C
3 A D11 D12 E
I want to be able to count each distinct value in those 4 columns, like :
value count
A11 2
A12 2
C 3
B11 1
D11 2
D12 1
E12 3
B 1
A 1
E 1