Frequency Counting in Python.

One of the most frequent operations when doing data analysis is looking at the frequency counts information.

I wanted to list down the various ways of doing this task:

  • using python collections: Counter and Defaultdict
  • using numpy
    • with numpy.unique, with return_counts argument
    • with bincount, nonzero, zip / vstack
  • using pandas
  • using scipy

 

References:

Code:

 

 

Getting started with Numpy

One of the best getting started guides on Numpy is the stanford tutorial.

http://cs231n.github.io/python-numpy-tutorial/

For numpy broadcasting, this is a great guide:

 

References: