您可以先使用
loc来查找
nan该
ids列中所有具有的行,然后使用
at将它们的值设置为空列表来遍历这些行:
for row in df.loc[df.ids.isnull(), 'ids'].index: df.at[row, 'ids'] = []>>> df date ids0 2011-04-23 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]1 2011-04-24 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]2 2011-04-25 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]3 2011-04-26 []4 2011-04-27 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]5 2011-04-28 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]


![如何在熊猫中用空列表[]填充数据框Nan值? 如何在熊猫中用空列表[]填充数据框Nan值?](http://www.mshxw.com/aiimages/31/626335.png)
