Issue
I have a pandas dataframe that looks like the following. I want to get rid of the single quotes of the strings in the list. Any suggestion is appreciated.
name relations
0 mary ['andrew', 'jane']
1 jack ['priscilla', 'mary']
2 jason ['howard', 'jackie']
Expected output
name relations
0 mary [andrew, jane]
1 jack [priscilla, mary]
2 jason [howard, jackie]
Solution
The string becomes an object and displays an error if is not defined. But it should do what you need.
df['relations'] = df['relations'].apply(lambda x: list(map(eval,x)))
Answered By - darthbane426
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.