I have seen :
How do I find the closest values in a Pandas series to an input number?
I have a pandas DataFrame like this :
| idx | col1 | col2 | 
|---|---|---|
| 1 | 2 | 56 | 
| 2 | 3 | 22 | 
| 3 | 6 | 12 | 
| 4 | 7 | 7 | 
| 5 | 7.5 | 6 | 
| 6 | 9 | 9 | 
| 7 | 10.1 | 11 | 
| 8 | 11 | 23 | 
and an input list like this :
[ 4, 7.6, 10]
I want to keep the same number of rows as the list length, where the elements in df['col1'] are the closest to the elements in the list such that y output DataFrame is :
| idx | col1 | col2 | 
|---|---|---|
| 2 | 3 | 22 | 
| 5 | 7.5 | 6 | 
| 7 | 10.1 | 11 | 
What is an efficient solution when dataframe and list get big?
 
     
     
    