Sampling one record per unique value (pandas, python)
Based on number of rows per user this might be faster:
df.sample(frac=1).drop_duplicates(['User'])
df1_user_sample_one = df1.groupby('User').apply(lambda x:x.sample(1))
Using DataFrame.groupby.apply and lambda function to sample 1
This is what you want:
df1.groupby('User').apply(lambda df: df.sample(1))
Without the extra index:
df1.groupby('User', group_keys=False).apply(lambda df: df.sample(1))