statistics.py 文件源码

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

项目:expan 作者: zalando 项目源码 文件源码
def sample_size(x):
    """
    Calculates sample size of a sample x
    Args:
        x (array_like): sample to calculate sample size

    Returns:
        int: sample size of the sample excluding nans
    """
    # cast into a dummy numpy array to infer the dtype
    x_as_array = np.array(x)

    if np.issubdtype(x_as_array.dtype, np.number):
        _x = np.array(x, dtype=float)
        x_nan = np.isnan(_x).sum()
    # assuming categorical sample
    elif isinstance(x, pd.core.series.Series):
        x_nan = x.str.contains('NA').sum()
    else:
        x_nan = list(x).count('NA')

    return len(x) - x_nan
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号