Replace NaN with empty list in a pandas dataframe

后端 未结 3 535
后悔当初
后悔当初 2021-01-04 02:11

I\'m trying to replace some NaN values in my data with an empty list []. However the list is represented as a str and doesn\'t allow me to properly apply the len() function.

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-04 02:34

    You can also use a list comprehension for this:

    d['x'] = [ [] if x is np.NaN else x for x in d['x'] ]
    

提交回复
热议问题