Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

pandas select random entry after groupby

size = 2        # sample size
replace = True  # with replacement
fn = lambda obj: obj.loc[np.random.choice(obj.index, size, replace),:]
df.groupby('Group_Id', as_index=False).apply(fn)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pandas #select #random #entry #groupby
ADD COMMENT
Topic
Name
9+9 =