utils.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:pymltk 作者: bkomboz 项目源码 文件源码
def mode(data=None):
    """
    Compute mode of given numpy array or pandas series.

    Mode is just a wrapper around scipy.stats.mode which returns
    the mode of a given numpy array or pandas series. Missing
    values are omitted before the mode is computed.

    Args:
        data: A numpy array or pandas series.

    Returns:
        The mode of x as scalar value.

    Raises:
        ValueError: If no data is specified or if all values are missing.
    """
    if data is None:
        raise ValueError('No data specified.')
    if not len(data.dropna()):
        raise ValueError('No valid data specified.')
    mode_val = stats.mode(data.dropna(), nan_policy='omit')[0]
    return mode_val[0]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号