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
评论列表
文章目录