Search
 
SCRIPT & CODE EXAMPLE
 

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)
Comment

PREVIOUS NEXT
Code Example
Python :: groupby and add aggregated column 
Python :: python code sample submission of codeforces 
Python :: make python present number in sciencetifc 
Python :: How many rows and columns are present in the dataframe? 
Python :: Fetch all links from a given webpage 
Python :: how to access specific index of matrix in python 
Python :: Python batch file rename 
Python :: How to secure an endpoint for selected users with Flask-JWT-Extended 
Python :: how to seperate the script from html template when using jQuery in flask 
Python :: Determining the Data Type 
Python :: how to blend pixels in pygame 
Python :: sqlalchemy validation at db level 
Python :: python request.args.get list 
Python :: replace string in dictionary python 
Python :: ring write the key and the IV directly using strings 
Python :: ring Load Syntax Files 
Python :: how to split from a specific charecter tfrm the end of string 
Python :: twitter api ("Connection broken: Invalid Chunk Length(got length b', 0 bytes read)" 
Python :: element wise mean and std 
Python :: instaed of: newlist = [] for word in wordlist: newlist.append(word.upper()) 
Python :: custom 3d image generator for segmentation 
Python :: ticklabels are not centered heatmap 
Python :: python making player equipment 
Python :: qcombobox remove all items 
Python :: text replace 
Python :: how to make a instagram report bot python 
Python :: identifying strings python 
Python :: ‘A’, ‘Q’, ‘BM’, ‘BA’, ‘BQ’ meaning in resample 
Python :: return positon of ele in list python 
Python :: Univariant Variable Analysis - Multiple Plots 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =