I'd like to create a lookup table from a dataframe based on multiple conditions. I have the following df:
N = 100
L = ['AR1', 'PO1', 'RU1']
np.random.seed(0)
df3 = pd.DataFrame(
{'X':np.random.uniform(1,4,N),
'Y':np.random.uniform(1,4,N),
'Z':np.random.uniform(1,4,N),
'LG':np.random.choice(L,N),
})
df3['bins_X'] = df3.groupby('LG')['X'].apply(pd.qcut, q=5, labels=np.arange(5))
df3['bins_Y'] = df3.groupby('LG')['Y'].apply(pd.qcut, q=5, labels=np.arange(5))
df3['bins_Z'] = df3.groupby('LG')['Z'].apply(pd.qcut, q=5, labels=np.arange(5))
df3['bins_X_int'] = df3.groupby('LG')['X'].apply(pd.qcut, q=5)
df3['bins_Y_int'] = df3.groupby('LG')['Y'].apply(pd.qcut, q=5)
df3['bins_Z_int'] = df3.groupby('LG')['Z'].apply(pd.qcut, q=5)
df3.head()
From which I want to create the following lookup_table:
So, grouped by 'LG' and the bins ranked from 0 to 4. What I need is the example lookup_table filled out with the associating bin_intervals from the dataframe.