I have a trivial question. I have a very large df with lots of columns. I am trying to find the most efficient way to bin all the columns with different bin sizes and create a new df. Here is an example for only binning a single column:
import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.randint(0,20,size=(5, 4)), columns=list('ABCD'))
newDF = pd.cut(df.A, 2, precision=0)
newDF
0 (9.0, 18.0]
1 (-0.0, 9.0]
2 (-0.0, 9.0]
3 (-0.0, 9.0]
4 (9.0, 18.0]
Name: A, dtype: category
Categories (2, interval[float64]): [(-0.0, 9.0] < (9.0, 18.0]]