boyenec
boyenec

Reputation: 1617

pandas how to replace only empty list data?

my dataframe look like this:

   variations_list1          variations_list2
    ["yellow","ornage"]          []
    ["xl","xxl"]                 []
    ["Burger","pizza"]         ["$25","$30"]

expected dataframe:

 variations_list1          variations_list2
    ["yellow","ornage"]         ["yellow","ornage"] #filling emty list with current row data
    ["xl","xxl"]                ["xl","xxl"]
    ["Burger","pizza"]         ["$25","$30"]

Upvotes: 0

Views: 80

Answers (1)

BENY
BENY

Reputation: 323226

You can just do

df.loc[~df['variations_list2'].astype(bool),'variations_list2'] = df['variations_list1']

You have the same issue like before, list is not list

df.loc[df['variations_list2']=='[]','variations_list2'] = df['variations_list1']

Upvotes: 2

Related Questions