我正在以这种格式输出。有什么办法可以将输出保存为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'}]
答案 0 :(得分:0)
result = pd.read_csv('filename')
result.to_csv('result.csv')
result.to_excel('result.xlsx')
result.to_html('result.htm')