__init__.py 文件源码

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

项目:mlprojects-py 作者: srinathperera 项目源码 文件源码
def fill_in_missing_dates(df, date_col_name, other_col):
    startd = df[date_col_name].values[0]
    endd = df[date_col_name].values[-1]
    print startd, endd
    idx = pd.date_range(startd, endd)

    dict = {}
    for index, row in df.iterrows():
        dict[row[date_col_name]] = row[other_col]

    new_data = []
    for d in idx:
        pydate = d.to_pydatetime()
        daskey = pydate.strftime('%Y-%m-%d')
        new_data.append([daskey, dict[daskey] if dict.has_key(daskey) else None])

    return np.row_stack(new_data)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号