这是我的csv文件。
Uid,Message,Status
9425252526,Hello 1,0
9425252527,Hello 2,0
9425252528,Hello 3,0
9425252529,Hello 4,0
9425252530,Hello 5,0
如果我将它转换为pandas数据帧并将其写回另一个文件,它会添加这个不需要的额外列,如下所示(最左边的列)
,Uid,Message,Status
0,9425252526,Hello 1,0
1,9425252527,Hello 2,0
2,9425252528,Hello 3,0
3,9425252529,Hello 4,0
4,9425252530,Hello 5,0
如何删除此列?
答案 0 :(得分:2)
假设您将数据框命名为df
。您需要将index
设置为false
:
df.to_csv("yourFile.csv", index=False)
答案 1 :(得分:1)
您需要将index=False
添加到to_csv
:
print df.to_csv(index=False)
"Uid,Message,Status"
"9425252526,Hello 1,0"
"9425252527,Hello 2,0"
"9425252528,Hello 3,0"
"9425252529,Hello 4,0"
"9425252530,Hello 5,0"
或filename
:
df.to_csv('filename', index=False)