我试图压缩其中包含nan
的python3列表并导致错误。
我用来压扁列表的代码是
def flatten(x):
if isinstance(x, collections.Iterable):
return [a for i in x for a in flatten(i)]
else:
return [x]
来自Flatten (an irregular) list of lists的。它适用于像这样的列表
[1,[123,132], 1]
但它在我的列表[nan, ['fiction', 'flash', 'short-story'], nan, nan, nan]
上不起作用
nans来自pandas DataFrame中的空白区域。
我收到错误RuntimeError: maximum recursion depth exceeded in cmp