4

I have a bunch of columns with "julian date" type in pandas. What would be the best possible way to convert them to gregorian dates. My dataframe looks like -

    CODE     START_DATE     END_DATE
0  00200         115001       115365
1  00200         115001       115365
2  00200         115001       115365
3  00200         115001       115365
4  00200         115001       115365

I would want to convert the START_DATE & END_DATE columns to gregorian/regular datetime.

In sql, I would use the below -

UPDATE Table1 set
DATE_NEW = CASE WHEN ltrim(rtrim(START_DATE)) = 0 THEN '1900-01-01' 
    WHEN ltrim(rtrim(START_DATE)) IS NULL THEN NULL    
    ELSE (CAST(DATEADD(dayofyear , ltrim(rtrim(START_DATE)) % 1000 - 1,DATEADD(year, ltrim(rtrim(START_DATE)) / 1000 , '1900-01-01')) as date)) END 

Please suggest. Thanks.

0nir
  • 1,345
  • 4
  • 20
  • 41

0 Answers0