【发布时间】:2021-01-09 23:53:00
【问题描述】:
我有两张均值表和标准值表,我想计算均值表某些列的最大值,并且我想得到标准值表的对应行。
mean_df = pd.read_csv(r'./csvs/mean.csv')
std_df = pd.read_csv(r'./csvs/std.csv')
#mean_df, std_df are of same size
grouped_df = mean_df.groupby(['alpha', 'beta'])
columns = ['val']
max_df = grouped_df[columns].agg(['max'])
# Here i want the corresponding std_max_df table for the max_df. i.e., for every max calculated from mean, i want the std of that max in a new table.
例如:
输入 mean_df 是
阿尔法贝塔伽马值
1 2 3 100
4 6 8 200
1 2 9 400
4 6 7 500
3 5 8 600
输入 std_df 是
阿尔法贝塔伽马值
1 2 3 300
4 6 8 500
1 2 9 100
4 6 7 700
3 5 8 900
输出将是
alpha beta gamma max_mean_val corresp_std_val
1 2 9 400 100
4 6 7 500 700
3 5 8 600 900
【问题讨论】:
-
您的问题到底是什么?请阅读How do I ask a good question?。特别是“在发布任何代码之前介绍问题”部分。
-
您现在可以调查一下吗?我基本上有两个表,我计算表 1 中某些列的最大值,我想要表 2 中的相应行
标签: python pandas csv pandas-groupby