Python csvwriter未写入csv文件
我是python新手,我对csv模块有问题 我的代码成功创建了csv文件,但csv文件仍然为空 这是我的密码:Python csvwriter未写入csv文件,python,csv,tensorflow,Python,Csv,Tensorflow,我是python新手,我对csv模块有问题 我的代码成功创建了csv文件,但csv文件仍然为空 这是我的密码: with open('log.csv', 'w') as stream: csvwriter = csv.writer(stream, delimiter=',', quotechar='"') for i in range(0, 200): model.train(input_fn=train_input_fn, steps=100)
with open('log.csv', 'w') as stream:
csvwriter = csv.writer(stream, delimiter=',', quotechar='"')
for i in range(0, 200):
model.train(input_fn=train_input_fn, steps=100)
evaluation_result = model.evaluate(input_fn=test_input_fn)
predictions = list(model.predict(input_fn=test_input_fn))
prediction_result = betting.test_betting_stategy(predictions, test_features, test_labels)
csvwriter.writerow([(i + 1) * 100, evaluation_result['accuracy'], evaluation_result['average_loss'], prediction_result['performance']])
stream.close()
我的问题是如何让python刷新到磁盘并写入csv文件?在csvwriter.writerow()之后使用stream.flush()
好的。正如我所说,我是python的新手,现在我得到了缩进的值
下面的代码非常完美
with open('log.csv', 'w') as stream:
csvwriter = csv.writer(stream, delimiter=',', quotechar='"')
for i in range(0, 200):
model.train(input_fn=train_input_fn, steps=100)
evaluation_result = model.evaluate(input_fn=test_input_fn)
predictions = list(model.predict(input_fn=test_input_fn))
prediction_result = betting.test_betting_stategy(predictions, test_features, test_labels)
csvwriter.writerow([(i + 1) * 100, evaluation_result['accuracy'], evaluation_result['average_loss'], prediction_result['performance']])
stream.flush() **#This indentation works perfectly!!!**
你确定你的模型<代码>火车代码>和<代码>预测代码>已经完成了吗?有时需要一段时间。我会确认的。很有洞察力。