Just looking forward a solution to remove empty values from a column which has values as a list in a sense where we are already replacing some strings beforehand, where it's a column of string representation of lists.
In df.color we are Just replacing *._Blue with empty string:
Example DataFrame:
df = pd.DataFrame({ 'Bird': ["parrot", "Eagle", "Seagull"], 'color': [ "['Light_Blue','Green','Dark_Blue']", "['Sky_Blue','Black','White', 'Yellow','Gray']", "['White','Jet_Blue','Pink', 'Tan','Brown', 'Purple']"] })
>>> df
Bird color
0 parrot ['Light_Blue','Green','Dark_Blue']
1 Eagle ['Sky_Blue','Black','White', 'Yellow','Gray']
2 Seagull ['White','Jet_Blue','Pink', 'Tan','Brown', 'Pu...
Result of above DF:
>>> df['color'].str.replace(r'\w+_Blue\b', '')
0 ['','Green','']
1 ['','Black','White', 'Yellow','Gray']
2 ['White','','Pink', 'Tan','Brown', 'Purple']
Name: color, dtype: object
Usually in python it easily been done as follows..
>>> lst = ['','Green','']
>>> [x for x in lst if x]
['Green']
I'm afraid if something like below can be done.
df.color.mask(df == ' ')
to_dictto create a minimal reproducible example, so that it is easy to re-create.