Skip to content

Instantly share code, notes, and snippets.

@tbrittoborges
Last active May 20, 2016 11:16
Show Gist options
  • Save tbrittoborges/9bbb5ff9fb0465e080b435c76a707ae4 to your computer and use it in GitHub Desktop.
Save tbrittoborges/9bbb5ff9fb0465e080b435c76a707ae4 to your computer and use it in GitHub Desktop.
Pandas unlistfy one colum
df['new'] = df['new'].str.split('/') # example how to listfy a column of strings
temp = pd.DataFrame(df['new'].dropna().tolist())
temp = temp.stack()
temp.index = temp.index.droplevel(1) # index need to be coherent with the original dataframe
temp.name = 'new_colum' # name of the new column in the original dataframe
df = df.join(temp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment