From c3a30ae0b33efd3cc0fdfc8881d73628558a9df9 Mon Sep 17 00:00:00 2001 From: 64457072af1fe407c29f45ae <64457072af1fe407c29f45ae@devide> Date: Sun, 23 Apr 2023 17:56:51 +0000 Subject: [PATCH] Auto commit --- ...1\271\351\207\217\347\273\237\350\256\241" | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 "\346\211\271\351\207\217\347\273\237\350\256\241" diff --git "a/\346\211\271\351\207\217\347\273\237\350\256\241" "b/\346\211\271\351\207\217\347\273\237\350\256\241" new file mode 100644 index 0000000..8727c3b --- /dev/null +++ "b/\346\211\271\351\207\217\347\273\237\350\256\241" @@ -0,0 +1,65 @@ +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 -- GitLab