histogram_filling.py 文件源码

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

项目:Eskapade 作者: KaveIO 项目源码 文件源码
def value_to_bin_center(val, **kwargs):
    """Convert value to bin center

    Convert a numeric or timestamp column to a common bin center value.

    :param bin_width: bin_width value needed to convert column to a common bin center value
    :param bin_offset: bin_offset value needed to convert column to a common bin center value
    """

    try:
        # NOTE this notation also works for timestamps, and does not change the
        # unit
        bin_width = kwargs.get('bin_width', 1)
        bin_offset = kwargs.get('bin_offset', 0)
        bin_index = int(np.floor((val - bin_offset) / bin_width))
        obj_type = type(bin_width)
        return bin_offset + obj_type((bin_index + 0.5) * bin_width)
    except BaseException:
        pass
    return val
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号