Skip to content

Instantly share code, notes, and snippets.

@ravishchawla
Last active June 6, 2019 17:36
Show Gist options
  • Save ravishchawla/09814c4f787e5d60ad8e14ad64f8b16a to your computer and use it in GitHub Desktop.
Save ravishchawla/09814c4f787e5d60ad8e14ad64f8b16a to your computer and use it in GitHub Desktop.
'''Cleaning the *Portfolio* dataset'''
# Dummy-fy channel attributes
portfolio_channels = portfolio['channels'].apply(lambda x: ' '.join(x)).str.get_dummies(' ');
portfolio_channels.columns = ['channel_' + col for col in portfolio_channels.columns];
# Dummy-fy offer type attributes
portfolio_offertype = portfolio['offer_type'].str.get_dummies()
portfolio_offertype.columns = ['offer_' + col for col in portfolio_offertype.columns];
# Add dummy columns and drop existing
portfolio = pd.concat([portfolio, portfolio_channels, portfolio_offertype], axis=1);
portfolio = portfolio.drop(['channels', 'offer_type'], axis=1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment