【发布时间】:2019-11-07 14:30:57
【问题描述】:
我得到这种格式的输出。有什么办法可以将此输出保存为 CSV 格式?
print("Source rule: {} \t similarity with Target Rule is \n {}\n".format(rule, sim_scores))
print("\n")
输出:
Source rule: 2.1 Separation of trains similarity with Target Rule is
[{'Cosine Sim Score': 1.0, 'Target Rule': '2.1 Separation of Trains'}]
Source rule: 2.1.1 Context similarity with Target Rule is
[{'Cosine Sim Score': 1.0000001, 'Target Rule': '2.1.1 - Context'}, {'Cosine Sim Score': 1.0000001, 'Target Rule': '2.2.1 Context'}, {'Cosine Sim Score': 1.0000001, 'Target Rule': '2.3.1 Context'}, {'Cosine Sim Score': 1.0000001, 'Target Rule': '2.4.1 Context'}, {'Cosine Sim Score': 1.0000001, 'Target Rule': '2.5.1 Context'}, {'Cosine Sim Score': 1.0000001, 'Target Rule': '2.6.1 Context'}, {'Cosine Sim Score': 1.0000001, 'Target Rule': '2.7.1 Context'}, {'Cosine Sim Score': 1.0000001, 'Target Rule': '2.8.1 Context'}, {'Cosine Sim Score': 1.0000001, 'Target Rule': '2.9.1 Context'}]
【问题讨论】:
-
另存为txt文件。 CSV 对于这种输出毫无用处。
-
我该怎么做?
-
是否可以在 pandas 中使用 .format()?
标签: python pandas csv printing output