cleaner.py 文件源码

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

项目:DSI-personal-reference-kit 作者: teb311 项目源码 文件源码
def dummify(df):
    '''
        Given a dataframe, for all the columns which are not numericly typed already,
        create dummies. This will NOT remove one of the dummies which is required for
        linear regression.

        returns DataFrame -- a dataframe with all non-numeric columns swapped into dummy columns
    '''
    obj_cols = []
    for cname in df.columns:
        if df[cname].dtype == object:
            obj_cols.append(cname)

    df = pd.get_dummies(df, columns=obj_cols)
    # for cname in obj_cols:
    #     del df[cname]

    return df
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号