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
You can use the combine
method of a DataFrame with np.minimum
as the argument. np.minimum
has special handling for NaN and complex NaNs.
Indeed, the pandas docs for combine uses the np.minimum
function to illustrate a "true element-wise combine":
>>> df1 = pd.DataFrame({'A': [5, 0], 'B': [2, 4]})
>>> df2 = pd.DataFrame({'A': [1, 1], 'B': [3, 3]})
>>> df1.combine(df2, np.minimum)
A B
0 1 2
1 0 3