对于范围内的 i(0,len(num_vars)): variable_evaluation_3d_plot(df,num_vars[i],"lineasgn_grp","avgspend1_12","lineasgn")
我希望每次迭代时将variable_evaluation_3d_plot函数的输出打印在单独的word文件中。
您可以对代码进行一些修改来实现此目的。
from docx import Document
def create_word_document(content, filename):
doc = Document()
doc.add_paragraph(content)
doc.save(filename)
num_vars = ["var1", "var2", "var3"]
for i in range(len(num_vars)):
content = variable_evaluation_3d_plot(df, num_vars[i], "lineasgn_grp", "avgspend1_12", "lineasgn")
filename = f"output_{num_vars[i]}.docx"
create_word_document(content, filename)