Creating an element-wise minimum Series from two other Series in Python Pandas

前端 未结 8 1487
南方客
南方客 2020-12-29 18:15

I am having trouble finding a way to do an efficient element-wise minimum of two Series objects in pandas. For example I can add two Series easily enough:

In         


        
8条回答
  •  一生所求
    2020-12-29 18:39

    Same answer as Andy Hayden, but a bit easier to read:

    >>> import pandas as pd
    >>> s1 = pd.Series(data=[1,2,3,4,5], index=[1,2,3,4,5])
    >>> s2 = pd.Series(data=[5,1,3,5], index=[1,2,3,4])
    >>> pd.DataFrame([s1, s2]).min()
    1    1.0
    2    1.0
    3    3.0
    4    4.0
    5    5.0
    dtype: float64
    

提交回复
热议问题