Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

pandas sample weights example

# Assuming you have a column with few category and you want to see more/few
# of some cateogry in your sample, then you can try the following code

# remember the weights must adds up to 1
                |____________________________________
                                      ↓      ↓      ↓
w = df['label'].apply( lambda x: {-1:0.5, 0:0.4, 1:0.1}[x] )
df.sample(n=1, weights=w, axis=0)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pandas #sample #weights
ADD COMMENT
Topic
Name
4+6 =