Created
January 17, 2018 16:34
-
-
Save rafaelnovello/f2fd64dd4a7240c32a37461e8dc77758 to your computer and use it in GitHub Desktop.
Code to duplicate row for each value in an array cell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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