我无法替换对象类型列中的'NaT'字符串。
代码print(d['cancellation_month'].dtype)
d['cancellation_month'] = d['cancellation_month'].replace('NaT', None)
print((d['cancellation_month'] == 'NaT').sum())
d.loc[d.cancellation_month == 'NaT', 'cancellation_month'] = None
print((d['cancellation_month'] == 'NaT').sum())
输出:
object
3
0
你是对的,你不能用replace
和value=None
如果value
为None
,且to_replace
不是字典,则设置为to_replace
parameter。因此,NaT
将被Nat
取代。
检查代码
if value is None:
# passing a single value that is scalar like
# when value is None (GH5319), for compat
if not is_dict_like(to_replace) and not is_dict_like(regex):
to_replace = [to_replace]