Skip to content

Instantly share code, notes, and snippets.

@socratesk
Created August 8, 2018 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save socratesk/d7975a159b2038a5d9e70fe343bdc829 to your computer and use it in GitHub Desktop.
Save socratesk/d7975a159b2038a5d9e70fe343bdc829 to your computer and use it in GitHub Desktop.
import pandas as pd
gadgetDF = pd.DataFrame({'gadgetId' : [101, 102, 103, 104, 105],
'gadgetName' : ['Apple_iPhone_6',
'Apple_iPad_3',
'Samsung_Galaxy_S8',
'Samsung_Galaxy_S9',
'Google_Pixel_3']})
dummyDF = gadgetDF['gadgetName'].apply(lambda x: pd.Series(x.split('_')))
dummyDF.columns = ['company', 'gadget', 'version']
gadgetDF = pd.concat([gadgetDF, dummyDF], axis=1)
gadgetDF = gadgetDF.drop(['gadgetName'], axis=1)
print(gadgetDF)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment