You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Excel中计算不同患者同位置行的Volume、Pressure列数值均值

解决方法

前置说明

默认所有患者的测量行数相同,每行的数值顺序均为Volume在前、Pressure在后,方案支持任意数量的患者批量计算。

方案1:Python + Pandas(适合大数据量场景)

代码示例:

import pandas as pd
import numpy as np

# 所有患者的数据统一存入该列表,新增患者仅需在列表中追加对应数据即可
patient_data_list = [
    # 患者1的测量数据:每行[Volume, Pressure]
    [[31, 15], [34, 35], [32, 44]],
    # 患者2的测量数据
    [[34, 23], [23, 23], [23, 24]]
]

# 批量转DataFrame后按行对齐求均值
df_list = [pd.DataFrame(data, columns=['Volume', 'Pressure']) for data in patient_data_list]
mean_patient_df = pd.DataFrame(np.mean([df.values for df in df_list], axis=0), columns=['Volume', 'Pressure'])

# 输出结果
print(mean_patient_df)

运行输出:

Volume  Pressure
0    32.5      19.0
1    28.5      29.0
2    27.5      34.0

方案2:纯Python实现(无需安装第三方依赖)

代码示例:

# 所有患者的测量数据存入该列表
all_patients = [
    [[31,15], [34,35], [32,44]],
    [[34,23], [23,23], [23,24]]
]

patient_num = len(all_patients)
row_num = len(all_patients[0])
mean_result = []

# 逐行逐列计算均值
for row_idx in range(row_num):
    row_avg = []
    # 计算Volume列均值
    vol_total = sum(p[row_idx][0] for p in all_patients)
    row_avg.append(vol_total / patient_num)
    # 计算Pressure列均值
    press_total = sum(p[row_idx][1] for p in all_patients)
    row_avg.append(press_total / patient_num)
    mean_result.append(row_avg)

# 打印结果
print("Volume\tPressure")
for row in mean_result:
    print(f"{row[0]}\t{row[1]}")

如果你的原始数据是存储在文本文件中,可以先通过Patient关键字分割文本内容,自动提取每个患者的测量行转换为数值格式,无需手动录入数据。

内容的提问来源于stack exchange,提问作者mcnew

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 15:54:04