Auto commit

上级 df352508
import pandas as pd
import os
from threading import Thread
# 遍历多个文件夹获取所有excel文件
path1 = r''
path2 = r''
path3 = r''
path4 = r''
path5 = r''
path6 = r''
path7 = r''
path8 = r''
files1 = []
files2 = []
folder_paths1 = [path1, path2, path3, path4]
folder_paths2 = [path5, path6, path7, path8]
for folder_path in folder_paths1:
for root, dirs, filenames in os.walk(folder_path):
for filename in filenames:
if filename.endswith('.xlsx'):
files1.append(os.path.join(root, filename))
print('正在处理:', os.path.join(root, filename))
for folder_path in folder_paths2:
for root, dirs, filenames in os.walk(folder_path):
for filename in filenames:
if filename.endswith('.xlsx'):
files2.append(os.path.join(root, filename))
print('正在处理:', os.path.join(root, filename))
# 线程1执行
def thread1():
results1 = []
for file in files1:
df = pd.read_excel(file)
print(file)
count = df.iloc[:, 0].value_counts().shape[0]
results1.append([file, count])
result1_df = pd.DataFrame(results1, columns=['文件名', '第一列数量'])
result1_df.to_excel(os.path.join('', '结果1.xlsx'), index=False)
print('线程1执行完成!')
# 线程2执行
def thread2():
results2 = []
for file in files2:
df = pd.read_excel(file)
print(file)
count = df.iloc[:, 0].value_counts().shape[0]
results2.append([file, count])
result2_df = pd.DataFrame(results2, columns=['文件名', '第一列数量'])
result2_df.to_excel(os.path.join('B:\keyanshuju', '结果2.xlsx'), index=False)
print('线程2执行完成!')
# 执行线程
t1 = Thread(target=thread1)
t1.start()
t2 = Thread(target=thread2)
t2.start()
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册