将朱利安日期转换为数据框中的正常日期?

问题描述:

我在熊猫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.)