[英]python pandas to_csv appending mode generate unwanted unknown rows
using to_csv appending mode generates unwanted unknown rows. 使用to_csv附加模式会生成不需要的未知行。
For example: 例如:
check = [0,0,0]
df = pd.DataFrame([check])
df.to_csv('test.csv', index=False)
df = pd.DataFrame([check])
df.to_csv('test.csv', mode='a', index=False)
df = pd.read_csv('test.csv')
returns 0 1 2 0 0 0 0 1 0 1 2 2 0 0 0
返回
0 1 2 0 0 0 0 1 0 1 2 2 0 0 0
where the 1 0 1 2 is unwanted and unknown extra row. 其中1 0 1 2是多余的,并且未知的额外行。
What is the problem here? 这里有什么问题?
Found that the extra unwanted row 1 0 1 2
is the columns' name. 发现多余的多余行
1 0 1 2
是列的名称。 Then I just tried following 然后我只是尝试跟随
check = [0,0,0]
df = pd.DataFrame([check])
df.to_csv('test.csv', index=False)
df = pd.DataFrame([check])
df.to_csv('test.csv', mode='a', index=False, header=False)
df = pd.read_csv('test.csv')
returns 回报
0 1 2
0 0 0 0
1 0 0 0
with header=False
to ignore the header/columns'name, then it returns what I want. 用
header=False
忽略标题/列的名称,然后返回我想要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.