Last active
April 16, 2021 03:04
-
-
Save thanakijwanavit/199cc690d5920cfd9066cca129d5eb93 to your computer and use it in GitHub Desktop.
convert string list to list in dataframe
This file contains hidden or 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
# for a list that looks like this | |
''' | |
“[strawberry, apple, orange]” | |
[credit](https://towardsdatascience.com/dealing-with-list-values-in-pandas-dataframes-a177e534f173) | |
''' | |
def clean_alt_list(list_): | |
list_ = list_.replace(', ', '","') | |
list_ = list_.replace('[', '["') | |
list_ = list_.replace(']', '"]') | |
return list_ | |
df['col'].apply(clean_al_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment