functions.py 文件源码

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

项目:seniority_list 作者: rubydatasystems 项目源码 文件源码
def align_fill_down(l, u,
                    long_indexed_df,
                    long_array):
    '''Data align current values to all future months
    (short array segment aligned to long array)
    This function is used to set the values from the last standalone month as
    the initial data for integrated dataset computation when a delayed
    implementation exists.
    uses pandas df auto align - relatively slow
    TODO (for developer) - consider an all numpy solution
    inputs
        l, u (integers)
            current month slice indexes (from long df)
        long_indexed_df (dataframe)
            empty long dataframe with empkey indexes
        long_array (array)
            long array of multiple month data
            (orig_job, fur_codes, etc)
    declare long indexed df outside of function (input).
    grab current month slice for array insertion (copy).
    chop long df to begin with current month (copy).
    assign array to short df.
    data align short df to long df (chopped to current month and future).
    copy chopped df column as array to long_array
    return long_array
    '''
    short_df = long_indexed_df[l:u].copy()
    short_df['x'] = long_array[l:u]
    # chopped_df begins with a defined index (row), normally the begining of
    # a delayed implementation month
    chopped_df = long_indexed_df[l:].copy()
    # data align short_df to chopped_df
    chopped_df['x'] = short_df['x']
    result_array = chopped_df.x.values
    result_size = result_array.size
    np.copyto(long_array[-result_size:], result_array)

    return long_array


# ALIGN NEXT (month)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号