如何在 c++/python 或使用任何其他 linux 命令中对第一列的退化值取第二列的平均值?

How can I take average of second column for degenerate values of first column in c++/python or using any other linux command?

我在一个文本文件中有一组数据,分为两列。我想要的是计算第一列中重复数字的平均值。例如对于前三行,取第二列的平均值,依此类推。如果您能提供任何帮助,我将不胜感激。

0.628319 0.123401

0.628319 0.23044

0.628319 4.57734

0.888577 0.390783

1.40496 0.110672

1.40496 0.239377

1.40496 0.248376

1.40496 0.751108

1.40496 0.971678

1.40496 1.36865

将数据放入 Excel 文件并将其读入 Pandas DataFrame。计算按第一列分组的第二列的平均值。

import pandas as pd


# header=None because there are no column headers in my XLSX file
# Column names will be integers: 0 and 1
data = pd.read_excel("physics.xlsx", header=None, engine="openpyxl")

# What does "grouped means" mean?: Sort column 1 values by column 0 value and take mean of each column-1 group
grp_means = data.groupby(0).mean()
print(grp_means)