You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何基于两点连线的斜率筛选pandas DataFrame中的数据

可视化图表
用户绘图参考代码:

ax = sns.scatterplot("inverse_docking_score","MW",hue="QPlogPoct",data=df1)
sns.lineplot(data=slope_data, x="X", y="Y")

实现方案

  1. 推导参考直线方程
    参考直线由两点 (10.5, 300)、(12.0, 450) 确定,代入直线通用公式 y = kx + b 计算参数:
  • 斜率 k = (450 - 300)/(12.0 - 10.5) = 100
  • 截距 b = 300 - 100*10.5 = -750
    直线最终表达式为:MW = 100 * inverse_docking_score - 750
  1. 筛选直线下方数据
    直线下方的点满足 MW < 对应x在直线上的y值,直接用pandas布尔索引筛选即可:
# 直接使用计算好的参数筛选
df_filtered = df1[df1['MW'] < 100 * df1['inverse_docking_score'] - 750].copy()

如果需要适配slope_data的动态调整,可自动提取两点计算参数,无需手动计算:

# 从slope_data动态计算直线参数
x1, y1 = slope_data.iloc[0]
x2, y2 = slope_data.iloc[1]
k = (y2 - y1) / (x2 - x1)
b = y1 - k * x1

# 筛选符合条件的数据
df_filtered = df1[df1['MW'] < k * df1['inverse_docking_score'] + b].copy()

内容的提问来源于stack exchange,提问作者David Kouvchinov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 16:27:00