我是Python的新手。
假设我在一个文本文件中保存了以下非常简单的表格:
one two three
four five six
seven eight nine
我可以使用pandas:查看此表
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)
中可以看出,第一行没有被赋予索引。
我确实试过用谷歌搜索这个,但没能找到答案。这可能是因为我不知道一些关键词。
One Two Three是CSV文件的头。所以要跳过它,请写下面提到的代码:
df=pd.read_csv('table.txt',header=none(