2024-09-30 00:36:18 发布
网友
当我计算下面的代码片段时,得到值True
True
import pandas as pd df = pd.DataFrame({'a': ['assa', '100', 'AJSAND']}) (df < 0).all()
在数据帧中字符串的计算值总是小于零吗?你知道吗
但是,以下操作会导致错误
's' < 0
如果您检查pandas的源代码,您可以在comp\method\FRAME方法下找到以下行。你可以找到一个完整的解释here。总之,它更多的是一种在不产生异常的情况下比较每种类型的方法。你知道吗
def _comp_method_FRAME(cls, func, special): str_rep = _get_opstr(func, cls) op_name = _get_op_name(func, special) @Appender('Wrapper for comparison method {name}'.format(name=op_name)) def f(self, other): if isinstance(other, ABCDataFrame): # Another DataFrame if not self._indexed_same(other): raise ValueError('Can only compare identically-labeled ' 'DataFrame objects') return self._compare_frame(other, func, str_rep) elif isinstance(other, ABCSeries): return _combine_series_frame(self, other, func, fill_value=None, axis=None, level=None, try_cast=False) else: # straight boolean comparisons we want to allow all columns # (regardless of dtype to pass thru) See #4537 for discussion. res = self._combine_const(other, func, errors='ignore', try_cast=False) return res.fillna(True).astype(bool) f.__name__ = op_name return f
所以基本上,数据帧首先填充nan,然后用真布尔值删除!你知道吗
如果您检查pandas的源代码,您可以在comp\method\FRAME方法下找到以下行。你可以找到一个完整的解释here。总之,它更多的是一种在不产生异常的情况下比较每种类型的方法。你知道吗
所以基本上,数据帧首先填充nan,然后用真布尔值删除!你知道吗
相关问题 更多 >
编程相关推荐