我的資料框如下所示:
variations_list1 variations_list2
["yellow","ornage"] []
["xl","xxl"] []
["Burger","pizza"] ["$25","$30"]
預期資料框:
variations_list1 variations_list2
["yellow","ornage"] ["yellow","ornage"] #filling emty list with current row data
["xl","xxl"] ["xl","xxl"]
["Burger","pizza"] ["$25","$30"]
uj5u.com熱心網友回復:
你可以做
df.loc[~df['variations_list2'].astype(bool),'variations_list2'] = df['variations_list1']
你有和以前一樣的問題,串列不是串列
df.loc[df['variations_list2']=='[]','variations_list2'] = df['variations_list1']
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/485530.html
標籤:Python python-3.x 熊猫
上一篇:如何將字典“附加”到嵌套字典中
