Randomly selecting from Pandas groups with equal probability — unexpected behavior
问题 I have 12 unique groups that I am trying to randomly sample from, each with a different number of observations. I want to randomly sample from the entire population (dataframe) with each group having the same probability of being selected from. The simplest example of this would be a dataframe with 2 groups. groups probability 0 a 0.25 1 a 0.25 2 b 0.5 using np.random.choice(df['groups'], p=df['probability'], size=100) Each iteration will now have a 50% chance of selecting group a and a 50%