如何通过创建2列将字符串写到Python中的CSV文件中?

时间:2019-06-27 08:50:02

标签: python string pandas csv io

假设我有一个loop,其执行方式如下:-

    for i in range(len(X_test)):
      _, _, ref, hyp = result([X_test[i]],y_test.iloc[i])
      hyp = hyp.replace('<end>', '')
      bleu_score = bleu([ref], hyp, smoothing_function=cc.method3)
      print("Associated BLEU score:",bleu_score,"\n")
      overall_bleu.append(bleu_score)

我想做的是创建一个新的CSV文件,该文件有2列,即Reference (Stands for ref variable in the loop)Predicted (Stands for hyp variable in the loop),这样对于每一行,在循环的每个连续迭代中,字符串{{1 }}和hyp写入新CSV文件(我要创建)的相应列中。有什么干净的方法吗?我本来打算使用ref,但似乎每次在循环中编写都是多余的。

1 个答案:

答案 0 :(得分:-1)