在 Pandas 中删除行时如何忽略 \N 转义?

How to ignore \N escape when dropping rows in Pandas?

我在 Pandas 中有一个数据框,其中包含一个用 \N 值填充的列(数据类型 = 对象)。我尝试使用下面的代码删除行并收到 unicode 错误。

df = df.drop(df['birth_year'] == '\N')


 File "<ipython-input-17-91f65c6f54c3>", line 1
    df = df.drop(df['birth_year'] == '\N')
                                    ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-1: malformed \N character escape

我该如何解决这个问题?

'\N' 是 Python 中的非法字符,尝试小写值然后删除值,并更改删除它的方式,例如:

df = df[df['birth_year'].str.lower() != '\n']