Skip to content

Instantly share code, notes, and snippets.

@rafaelnovello
Created January 17, 2018 16:34
Show Gist options
  • Save rafaelnovello/f2fd64dd4a7240c32a37461e8dc77758 to your computer and use it in GitHub Desktop.
Save rafaelnovello/f2fd64dd4a7240c32a37461e8dc77758 to your computer and use it in GitHub Desktop.
Code to duplicate row for each value in an array cell
def flat(df):
new = pd.DataFrame()
for i, s in df.iterrows():
emails = s['emails'].strip('[]').replace("'", "").split(',')
for e in emails:
x = s.copy()
x['emails'] = e
new = new.append(x, ignore_index=True)
return new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment