Search
 
SCRIPT & CODE EXAMPLE
 

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

PREVIOUS NEXT
Code Example
Python :: Use xarray to open a ncdf file 
Python :: python adding an item 
Python :: python sumproduct excel 
Python :: dict keys in tcl 
Python :: find all html files in a current directory using regular expression in python 
Python :: counter and element of list for loop python 
Python :: Loading data from Oracle Database to pandas DataFrames 
Python :: How to srape all links from a website in python 
Python :: Broadcasting with NumPy Arrays Example 
Python :: Python NumPy moveaxis function Example 
Python :: Django merge duplicate rows 
Python :: odoo 15 documentation 
Python :: Python NumPy asmatrix Function Syntax 
Python :: Python NumPy vstack Function Example with 1d array 
Python :: making dividers in tkinter 
Python :: python os.listdir attributes 
Python :: Python __ge__ 
Python :: NumPy resize Example out of bound values [appending zeros] 
Python :: python multiply function with return keyword 
Python :: NumPy binary_repr Syntax 
Python :: How to use "to_representation" hook for django rest serializers 
Python :: how to calculate iqr in pandas 
Python :: LCS Problem Python 
Python :: beautifulsoup - extracting link, text, and title within child div 
Python :: pydantic model from dataclass 
Python :: installing blacksheep 
Python :: Flask application displaying list of items from SQL database as text 
Python :: variable bound to set python 
Python :: flask login attemted_user cant see check_password_correction method 
Python :: ring retrieves the list of all algorithms supported by Encrypt()/Decrypt() functions. 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =