📌  相关文章
📜  如何在列python代码示例中找到最接近的值

📅  最后修改于: 2022-03-11 14:45:47.637000             🧑  作者: Mango

代码示例1
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.