Let us assume we created a dataframe df using the code below. I have created a bin frequency count based on the 'value' column in df. Now how do I get the frequency count of these label=1 samples frequency count based on previous created bin? Obviously, I should not use qcut for those label = 1 samples to get the count, since the bin positions are not same as before.
import numpy as np import pandas as pd mu, sigma = 0, 0.1 theta = 0.3 s = np.random.normal(mu, sigma, 100) group = np.random.binomial(1, theta, 100) df = pd.DataFrame(np.vstack([s,group]).transpose()) df.columns = ['value','label'] factor = pd.qcut(df['value'], 5) factor_bin_count = pd.value_counts(factor)
Update: I took the solution from jeff