针对pulse-transit的工具
This commit is contained in:
30
calculate_average_correlation.py
Normal file
30
calculate_average_correlation.py
Normal file
@@ -0,0 +1,30 @@
|
||||
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}")
|
||||
Reference in New Issue
Block a user