Binning Data Values using Pandas

#Python #Pandas

Use the pd.cut function. The bins argument is using (] are the segments. The official documentation comes with detailed examples.

If pandas is not an option, one could use numpy.digitize to find which bin the elements belong to.

Published: by ;

LM (2021). 'Binning Data Values using Pandas', Datumorphism, 03 April. Available at: https://datumorphism.leima.is/til/programming/pandas/pandas-binning-values/.

Current Ref:

  • til/programming/pandas/pandas-binning-values.md