pandas中两个工作表中的最小值

时间:2017-06-26 21:29:52

标签: python pandas numpy

如何在特定列的两个工作表中找到最小值

假设,

worksheet 1

index    A   B   C
   0     2   3   4.28
   1     3   4   5.23

worksheet 2

index    A   B   C
    0    9   6   5.9
    1    1   3   4.1

通过比较C列,我想要一个答案,其中数据框看起来像

index      min(c)
    0       4.28
    1       4.1

1 个答案:

答案 0 :(得分:2)

使用np.fmin查找分钟

np.fmin(ws1.C, ws2.C)

index
0    4.28
1    4.10
Name: C, dtype: float64

<强>设置
其他人试试

ws1 = pd.DataFrame([
        [2, 3, 4.28],
        [3, 4, 5.23]
    ], pd.Index([0, 1], name='index'), list('ABC'))

ws2 = pd.DataFrame([
        [9, 6, 5.9],
        [1, 3, 4.1]
    ], pd.Index([0, 1], name='index'), list('ABC'))