提供思路自己完成吧
1、用 os.walk 加 if 判断将所有的csv 文件名读到list中
用glob 也可以
import glob
for x in glob.glob('*.csv'):
print(x)
2、用csv 库或 第三方库 panpds 循环处理上面list中的文件
3、用doc 库 写doc 文件。
pip install python-docx
import docx
import pandas as pd
# i am not sure how you are getting your data, but you said it is a
# pandas data frame
df = pd.DataFrame(data)
# open an existing document
doc = docx.Document('./test.docx')
# add a table to the end and create a reference variable
# extra row is so we can add the header row
t = doc.add_table(df.shape[0]+1, df.shape[1])
# add the header rows.
for j in range(df.shape[-1]):
t.cell(0,j).text = df.columns[j]
# add the rest of the data frame
for i in range(df.shape[0]):
for j in range(df.shape[-1]):
t.cell(i+1,j).text = str(df.values[i,j])
# save the doc
doc.save('./test.docx')