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

如何用Pandas筛选包含L=ball_snap的行及之后所有行

用Pandas提取指定行及之后所有行的方法

步骤1:定位目标行的索引

先找到包含L = ball_snap的行对应的索引值,假设存储该内容的列名为event(请替换成你数据中实际的列名):

# 获取第一个匹配行的索引
target_index = df[df['event'] == 'L = ball_snap'].index[0]

如果数据里有多行匹配L = ball_snap,想取最后一个匹配行的话,把index[0]改成index[-1]即可。

步骤2:生成新的DataFrame

从目标索引位置开始,截取到原DataFrame末尾的所有行:

new_df = df.loc[target_index:]

可选:处理目标行不存在的情况

如果不确定数据里是否存在目标行,可以加个判断避免报错:

if not df[df['event'] == 'L = ball_snap'].empty:
    target_index = df[df['event'] == 'L = ball_snap'].index[0]
    new_df = df.loc[target_index:]
else:
    print("未找到包含'L = ball_snap'的行")

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 03:24:24