0
点赞
收藏
分享

微信扫一扫

python NAT和Nan处理为空字符串

Sky飞羽 2022-03-11 阅读 206
python

  我的原始数据为

 

 处理方式:

import pandas as pd
import numpy as np

test = pd.read_excel('D:\zhangping179\Downloads\\test.xlsx')
test["发现日期"] = pd.to_datetime(test["发现日期"], errors='coerce')
test["发现日期"] = np.where(test.发现日期.notnull(), test.发现日期.dt.strftime('%Y-%m-%d'), '')
test["处理日期"] = pd.to_datetime(test["处理日期"], errors='coerce')
test["处理日期"] = np.where(test.处理日期.notnull(), test.处理日期.dt.strftime('%Y-%m-%d'), '')
test = test.fillna('')
print(test)

经过处理后的数据为:

 

举报

相关推荐

0 条评论