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

如何用一行代码在Pandas中跳过前13行并将第14行设为表头?

一行代码实现跳过前13行并将第14行设为DataFrame表头

直接用pandas.read_csv的header参数就能搞定,一行代码替代你原来的繁琐操作:

import pandas as pd

df = pd.read_csv("/content/gdrive/MyDrive/Kwan_27112020.txt", delimiter="\t", header=13)

原理说明:

  • header=13指定**第14行(0索引计数下的第13位)**作为DataFrame的表头
  • 该参数会自动跳过表头之前的所有行,不需要额外执行df.columns = df.iloc[0]和df = df[1:]这类操作
  • 针对你提供的示例数据,前13行是元数据,第13行(0索引)正好是包含Gene Symbol、strand、start的目标表头行,完美匹配需求

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 19:15:57