我相信你需要
to_datetime参数
origin:
df = pd.Dataframe({'julian':[2458072.5, 2458073.5]})df['date'] = pd.to_datetime(df['julian'], unit='D', origin='julian')print (df) julian date0 2458072.5 2017-11-151 2458073.5 2017-11-16
编辑:
某个日期时间有问题
OutOfBounds。
因此,首先检查时间戳限制:
In [66]: pd.Timestamp.minOut[66]: Timestamp('1677-09-21 00:12:43.145225')In [67]: pd.Timestamp.maxOut[67]: Timestamp('2262-04-11 23:47:16.854775807')
然后获得最小的朱利安日期时间(通过convertin在线,例如在此处):
maxdate = 2547338mindate = 2333836
然后添加
NaN超出范围的日期,例如
where:
df = pd.Dataframe({'julian':[2821676, 2547338, 1, 2333836]})maxdate = 2547338mindate = 2333836clean_dates = df['julian'].where(df['julian'].between(mindate, maxdate))print (clean_dates)0 NaN1 2547338.02 NaN3 2333836.0df['date'] = pd.to_datetime(clean_dates, unit='D', origin='julian')print (df) julian date0 2821676 NaT1 2547338 2262-04-10 12:00:002 1 NaT3 2333836 1677-09-21 12:00:00
最后将解决方案应用于您的数据-有2个值转换为
NaT:
print (df['MXPLD_DATE'][~df['MXPLD_DATE'].between(mindate, maxdate)])1217806 28216763167148 2821676Name: MXPLD_DATE, dtype: int64clean_dates = df['MXPLD_DATE'].where(df['MXPLD_DATE'].between(mindate, maxdate)) df['MXPLD_DATE'] = pd.to_datetime(clean_dates, unit='D', origin='julian')print (df['MXPLD_DATE'])0 2015-06-10 12:00:001 2015-05-12 12:00:002 2015-05-12 12:00:003 2015-05-12 12:00:004 2015-05-12 12:00:005 2015-05-12 12:00:006 2015-05-12 12:00:007 2015-05-12 12:00:008 2015-05-12 12:00:009 2015-05-12 12:00:0010 2015-05-12 12:00:00
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)