问题描述
我是Python的新手。
说我将以下非常简单的表保存在文本文件中:
one two three
four five six
seven eight nine
我可以使用熊猫查看此表:
import pandas as pd
df = pd.read_csv('table.txt')
print(df)
其结果是:
one two three
0 four five six
1 seven eight nine
现在,我想删除第一行(即one two three
)。我的第一个念头是写:
df.drop([0])
因为行和列从0开始编号。但这是因为它删除了第二行(即four five six
)。
因此,此问题的标题。如何删除没有索引号的行?因为从print(df)
看,第一行没有索引。
我确实尝试过使用Google进行搜索,但是找不到答案。这可能是因为我不知道某些关键字。
解决方法
一二三是CSV文件的标题。 因此,要跳过它,请编写以下代码:
df = pd.read_csv('table.txt',header = none)