Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to find the closest value in column python


	result_index = df['col_to_search'].sub(search_value).abs().idxmin()

#.sub(search_value) subtracts search_value from the df[col_to_search] to make the nearest value almost-zero,
#.abs() makes the almost-zero the minimum of the column,
#.idxmin() yields the df.index of the minimum value, or the closest match to search_value.
Comment

PREVIOUS NEXT
Code Example
Python :: findout not common values between two data frames 
Python :: check if element in list python 
Python :: discord.py send image from url 
Python :: unique values in dataframe column count 
Python :: pyqt5 image center 
Python :: how to reverse array in python 
Python :: swap variables in python 
Python :: print font size python 
Python :: python isset 
Python :: how to make python open a program/desktop app 
Python :: python print string name in pattern 
Python :: python tkinter text get 
Python :: python thousands separators 
Python :: python draw rectangle on image 
Python :: flask wtforms multiple select 
Python :: how to make python file executable 
Python :: read a file python 
Python :: xargs to copy file from text files to another directory 
Python :: decimal to binary in python 
Python :: python for/else 
Python :: php echo shorthand 
Python :: python iterating through a string 
Python :: if number is divisible by 3 python 
Python :: turtle star python 
Python :: how to create a set from a list in python 
Python :: add cooldown to command discord.py 
Python :: python dunder 
Python :: run python file from another python file 
Python :: check if array is monotonic python 
Python :: torch flatten 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =