我无法替换object类型的列中的“”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发布于 2021-10-13 20:03:25
您是对的,您不能在value=None中使用replace
如果value为None并且to_replace不是字典,则将该值设置为to_replace参数。因此,Nat将取代NaT。
检查code
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]https://stackoverflow.com/questions/69561453
复制相似问题