展平nan值会导致错误

时间:2017-07-25 17:01:09

标签: python list pandas nan

我试图压缩其中包含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

0 个答案:

没有答案