In google trends there is possibility to export data as CSV. Obtained CSV has the following structure:
Week,subject 1, subject 2
2004-01-04 - 2004-01-10,13,6
2004-01-11 - 2004-01-17,9,9
2004-01-18 - 2004-01-24,11,4
I know that there is DateObject[]
, but it contain only one date. I want to obtain stepped chart of subjects 1 and 2 in time domain, and calculate correlation of them in range between two given dates.
My problem is: how structure of data, should I use to represent time range?
As google trends calls the time variable "week" take
StringTake["2004-01-04 - 2004-01-10", 10]
to get the first day of the range, then use
DateList[{"2004-01-04", {"Year", "Month", "Day"}}]
to create a date list and
DateString[{2004, 1, 4, 0, 0, 0}, {"Week"}]
to express the time in terms of the calendar week of the year. So, the function
RangeToWeek[timerangestring_] := DateString[ DateList[{ StringTake[timerangestring, 10], {"Year", "Month", "Day"}}], {"Week"}]
gives for the firs date in your list 01, because the time span from 04.01.2004 to 10.01.2004 corresponds to the first callendar week of that year.