python - 将 NaT 替换为 0 天

标签 python python-3.x pandas

我有一个看起来是谎言的 pandas 数据框:

A      
3 days    
NaT       
4 days

有没有办法把 NaT 替换为 0 天?

谢谢, 埃德

最佳答案

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

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

前面提到的

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)

关于python - 将 NaT 替换为 0 天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49240881/

相关文章:

python - 快速 Pandas 过滤

python - Pandas 合并处理连接输出中的重复项

python - Seaborn 分类数据条形图,分组

python 3.7导入smbus ModuleNotFoundError没有名为 'smbus'的模块

python - 从列表中以相反的顺序删除短语

Python 3.5 Pyperclip 模块导入失败

python - 检查日期列表是否在日期范围列表之间

python pandas 计算数据框中日期范围的小时数

python - Gurobi:使用 addConstrs() 但表达式不正确

python - Py_Initialize 运行需要哪些文件?