pandas中出现TypeError: cannot replace ['\\N'] with method pad on a DataFrame的解决方式

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/guyu1003/article/details/86490582

在使用pandas时,利用dataframe的replace函数进行替换

df.replace(r'\N',None)

出现如下错误:

TypeError: cannot replace ['\\N'] with method pad on a DataFrame

原因是,http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.replace.html

The command s.replace('a', None) is actually equivalent to s.replace(to_replace='a',value=None, method='pad')

这时可以使用:

df.replace({r'\N': None})

解决,

出现这种问题主要是,替换的类型之间出现了错误。

s.replace({'a': None}) is equivalent to s.replace(to_replace={'a': None}, value=None, method=None):

猜你喜欢

转载自blog.csdn.net/guyu1003/article/details/86490582
今日推荐