将朱利安日期转换为数据框中的正常日期? [英] Convert Julian dates to normal dates in a dataframe?

查看:47
本文介绍了将朱利安日期转换为数据框中的正常日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在熊猫DF中有一个日期栏,上面有朱利安日期.如何将这些儒略日期转换为mm-dd-yyyy格式.

I have a date column in a pandas DF with Julian dates. How can I convert these Julian dates to mm-dd-yyyy format.

样本数据

     ORG   CHAIN_NBR  SEQ_NBR     INT_STATUS  BLOCK_CODE_1  DATA_BLOCK_CODE_1
0   523         1        0          A             C             2012183
1   523         2        1          I             A             2013025
2   521         3        1          A             H             2007067
3   513         4        1          D             H             2001046
4   513         5        1          8             I             2006075

我正在使用 jd2gcal 函数,但是它不起作用.我也在尝试编写这样的代码,但是没有用.

I was using jd2gcal function but it's not working. I was also trying to write a code like this but of no use.

for i,row in amna.iterrows():
    amna['DATE_BLOCK_CODE_1'] = datetime.datetime.strptime(row['DATE_BLOCK_CODE_1'], '%Y%j')

所需的输出:

    ORG   CHAIN_NBR  SEQ_NBR     INT_STATUS  BLOCK_CODE_1  DATA_BLOCK_CODE_1
0   523         1        0          A             C             mm-dd-yyyy
1   523         2        1          I             A             mm-dd-yyyy
2   521         3        1          A             H             mm-dd-yyyy
3   513         4        1          D             H             mm-dd-yyyy
4   513         5        1          8             I             mm-dd-yyyy

请帮助我.

推荐答案

julian = df.DATA_BLOCK_CODE_1.str[4:].str.extract("([1-9][0-9]?[0-9]?)")    
df["DATA_BLOCK_CODE_1"] = df.DATA_BLOCK_CODE_1.str[:4] + "-" + julian
df['DATA_BLOCK_CODE_1'] = pd.to_datetime(df['DATA_BLOCK_CODE_1'], format='%Y-%j')

正则表达式将要求数字以除0之外的任何数字开头.(我假设 DATA_BLOCK_CODE_1 是字符串类型.)

The regular expression would require the digits to start any digit but 0. (I assume DATA_BLOCK_CODE_1 is of string type.)

这篇关于将朱利安日期转换为数据框中的正常日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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