我有一个看起来像这样的数据集:
+------+---+----+-----+---+---+-------+
| Name | A | B | ... | X | Y | maxXY |
+------+---+----+-----+---+---+-------+
| John | 3 | 6 | | 3 | 1 | |
+------+---+----+-----+---+---+-------+
| Will | 2 | 3 | | 4 | 4 | |
+------+---+----+-----+---+---+-------+
| Dave | 2 | 7 | | 3 | 2 | |
+------+---+----+-----+---+---+-------+
| Pete | 1 | 21 | | 2 | 3 | |
+------+---+----+-----+---+---+-------+
我想从选择的列中计算行最大值,我将使用列ID 进行引用。像这样:
target_columns = [45,46] # X = 45, Y = 46
dataframe['maxXY'] = ...
非常感谢,
答案 0 :(得分:1)
这似乎可行:
dataframe['maxXY'] = np.max(dataframe.iloc[:, target_columns],axis=1)
答案 1 :(得分:1)
我们通常使用create unique index u_i on accounts(user_id, level_id) WHERE level_id = 'm';
pandas.DataFrame.max
答案 2 :(得分:0)
我相信np.max(dataframe[[dataframe.index[45],dataframe.index[46]].iloc[row_num].values)
可能会产生理想的结果。