sciPy function stats.itemfreq () | python

NumPy | Python Methods and Functions

scipy.stats.itemfreq (arr, axis = None) helps us calculate the frequencies of elements.

Parameters:
arr: [array_like] input array.

Results: 2D array with item frequency.

Code # 1: using variation()

# cumulative frequency

from scipy import stats

import numpy as np 

 

arr = [ 14 , 31 , 27 , 27 , 31 , 13 , 14 , 13

 

print ( "Itemfrequency:" , stats.itemfreq (arr))

 

print ( "Bincount:" , np.bincount (arr))

Exit:

 Itemfrequency: [[13 2] [14 2] [27 2] [31 2]] Bincount: [0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 2] 




Get Solution for free from DataCamp guru