I want to merge two columns (the year and day of year) and create a datetime index for my dataframe, but I can't seem to work out how to do it
my data (csv file) looks like...
YEAR, DOY, a
2001, 1, 10.
2001, 2, 11.
2001, 3, 67.
So I want to create the dataframe that looks something like
index YEAR DOY a
2001-01-01 00:00:00 2001 1 10.
2001-01-02 00:00:00 2001 2 11.
2001-01-02 00:00:00 2001 2 67.
import pandas
import datetime as dt
from cStringIO import StringIO
def date_converter(x):
print x
#return dt.datetime.strptime(str(2001) + ' ' + str(1), '%Y %j')
data = "YEAR, DOY, a\n2001, 1, 10.\n2001, 2, 11.\n2001, 3, 67."
df = pandas.read_csv(StringIO(data), sep=",", parse_dates=True,
index_col=[0,1], date_parser=date_converter)
However x is only the first part, i.e. the year and I can't seem to get both the year and doy.
thanks.