txt到csv添加了一个数字列



所以我有一个文本文件,里面有这个:

2117,1222
1212,1223
1322,1224
etc

我用这个代码把它放在一个CSV文件中:

read_file = pd.read_csv('file.txt')
read_file.to_csv('new_file.csv)

但当我运行它时,CSV文件看起来是这样的:

,2117,1222
0,1212,1223
1,1322,1224
etc

所以我不知道额外的0,1是什么,但我真的不知道如何阻止它被添加。非常感谢。

尝试:

read_file.to_csv('new_file.csv', index=False)

关于其他方法的参数确实值得一读(https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_csv.html)。read_file变量中仍然有这些索引值(请尝试打印(,但它将在outfile中消失。

最新更新