Pandas date and time with Julian Day

I tried to find this and was surprised that I did not find anything. We use the term “Julian day” to mean the day of the year regardless of the month (ie February 1 — Julian day 32). I do not know if this is a regional term, and perhaps why I can not find the answers.

I basically have two files. One has a standard date format: year, month, day, hour. Another has a year, Julian day, an hour. I am trying to align them using the pandas DataFrame function and do not know what to do with the missing month data. Can pandas convert this natively?

I am using python 3.3 and the latest version of Pandas.

Thanks!

+1
source share
2 answers

When you read Julian's date file, you just need to provide your own date parsing function. Here are some examples:

import datetime from io import StringIO import pandas datafile = StringIO("""\ jday,value 2013-01,1 2013-02,2 2013-100,8 2013-200,9 """) dateparser = lambda x: datetime.datetime.strptime(x, '%Y-%j') df = pandas.read_csv(datafile, parse_dates=True, date_parser=dateparser, index_col=[0]) 

What gives df of:

  value jday 2013-01-01 1 2013-01-02 2 2013-04-10 8 2013-07-19 9 

I save this bookmarked page and convenient for "non-traditional" date parsing such as these. (I really don't think Julian days are strange - we use them all the time in hydraulic modeling)

+4
source

Try dayofyear . Julian Day is actually a completely different FYI number, see here

 In [1]: pd.date_range('20130201',periods=5).dayofyear Out[1]: array([32, 33, 34, 35, 36], dtype=int32) 
+2
source

All Articles