나는 모양 test.csv
라는 CSV이 : 내가 뭐하는 거지추가 to_csv 모드는 다음 새 라인에 추가되지
accuracy threshold trainingLabels
def 0.116 342
dja 0.121 1271
하십시오 dataframe의 모습 summaryDF
라고 다음
accuracy threshold trainingLabels
abc 0.506 15000
eew 18.12 15000
과 :
try:
if os.stat('test.csv').st_size > 0:
summaryDF.to_csv(path_or_buf=f, encoding='utf-8', mode='a', header=False)
f.close()
else:
print "empty file"
with open('test.csv', 'w+') as f:
summaryDF.to_csv(path_or_buf=f, encoding='utf-8')
f.close()
except OSError:
print "No file"
with open('test.csv', 'w+') as f:
summaryDF.to_csv(path_or_buf=f, encoding='utf-8')
f.close()
내 파일을 다음과 같이 지정하고 싶습니다.
accuracy threshold trainingLabels
abc 0.506 15000
eew 18.12 15000
def 0.116 342
dja 0.121 1271
대신은 다음과 같습니다
accuracy threshold trainingLabels
abc 0.506 15000
eew 18.12 15000def 0.116 342
dja 0.121 1271
어떻게이 문제를 해결할 수 있습니까? to_csv
대신 CSV 라이터를 사용하고 있지만 추측하면 추가 모드는 기존 파일의 마지막 줄을 건너 뛰지 않습니다.