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

为何Pandas读取CSV后DataFrame索引从第二行开始?求解决

Fixing DataFrame Index Starting From the Second Row

Hey there! Let's break down what's going on here and fix that index issue quickly.

The Root Cause

When you saved your DataFrame to CSV using results.to_csv(..., header=None), you told pandas not to write column headers into the file. But when you read the CSV back with plain pd.read_csv(), pandas defaults to treating the first line of the file as the column headers.

That means your first actual data row (ROCO_CLEF_TEST_00001 ...) got turned into the column names of your new DataFrame, and your real data starts from the second line—so the index looks like it's starting from the second row.

The Simple Fix

Just add the header=None parameter when reading the CSV, matching what you did when writing it. This tells pandas the file has no header row, so it'll treat every line as data and assign the default index starting at 0 to your first data row.

Here's the corrected reading code:

kf = pd.read_csv('/home/udas/scratch/projekt01/results.csv', header=None)
print(kf.head())

Optional: Add Meaningful Column Names

If you want to reassign the original column names to your DataFrame while reading, use the names parameter:

kf = pd.read_csv(
    '/home/udas/scratch/projekt01/results.csv',
    header=None,
    names=["Picture", "predictions"]
)
print(kf.head())

This gives you both the correct index mapping and properly labeled columns.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 07:52:32