Comparing logical values to NaN in pandas/numpy

前端 未结 1 1264
旧时难觅i
旧时难觅i 2020-12-06 17:11

I want to do an element-wise OR operation on two pandas Series of boolean values. np.nans are also included.

I have tried three approaches and realized

相关标签:
1条回答
  • 2020-12-06 17:35

    first difference : | is np.bitwise_or. it explains the difference between #1 and #2.

    Second difference : since serie_1.dtype if object (non homogeneous data), operations are done row by row in the two first cases.

    When using vectorize ( #3):

    The data type of the output of vectorized is determined by calling the function with the first element of the input. This can be avoided by specifying the otypes argument.

    For vectorized operations, you quit the object mode. data are first converted according to first element (bool here, bool(nan) is True) and the operations are done after.

    0 讨论(0)
提交回复
热议问题