Files
Feature-Extraction/calculate_average_correlation.py

31 lines
908 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import pandas as pd
# 设置父文件夹路径
folder_path = "D://python_study//big_boss//doc//output"
# 获取所有子文件夹中的.xlsx文件
xlsx_files = []
for root, dirs, files in os.walk(folder_path):
for file in files:
if file.endswith('.xlsx'):
xlsx_files.append(os.path.join(root, file))
# 初始化一个空列表来存储所有数据框DataFrame
data_frames = []
# 读取每个文件并将其加入到列表中
for file in xlsx_files:
df = pd.read_excel(file)
data_frames.append(df)
# 计算每个位置单元格的平均数
# 这里假设所有表格具有相同的形状
average_df = pd.concat(data_frames, axis=0).groupby(level=0).mean()
# 将结果保存为新的.xlsx文件
output_path = "D://python_study//big_boss//doc//output//ave_corr.xlsx"
average_df.to_excel(output_path, index=False)
print(f"结果已保存到 {output_path}")