用 0 天替换 NaT [英] replacing NaT with 0 days

查看:49
本文介绍了用 0 天替换 NaT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来撒谎的熊猫数据框:

I have a pandas dataframe that looks lie:

A      
3 days    
NaT       
4 days

有没有办法用0天替换NaT?

Is there a way to replace the NaT with 0 days ?

谢谢,埃德

推荐答案

请注意,其他答案不再是最新的.首选语法是:

Please note that the other answers are not up to date anymore. The preferred syntax is:

df['column'].fillna(pd.Timedelta(seconds=0))

前面提到的

df['column'].fillna(0)

将导致:

FutureWarning:不推荐将整数传递给 fillna,将引发未来版本中的类型错误.要保留旧行为,请通过pd.Timedelta(seconds=n) 代替.df['column'] = df['column'].fillna(0)

FutureWarning: Passing integers to fillna is deprecated, will raise a TypeError in a future version. To retain the old behavior, pass pd.Timedelta(seconds=n) instead. df['column'] = df['column'].fillna(0)

这篇关于用 0 天替换 NaT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆