0
$\begingroup$

Thanks in advance for all your help.

I need to import data from a CSV file that looks like :(it's just easier to read in excel)

(easier to read in excel)

I would like to convert the data into timestamps by creating a Table with 2 columns in Mathematica. The first column I would like to have a timestamp using AbsoluteTime that combines the year, month, day, hour, minute (for example: the first entry would be 2012-1-1 0:00 which then would be converted into absolutetime). The second column would have the DHI values.

I did this earlier for another data set that had two columns:

enter image description here

by using this code:

precip = Table[{AbsoluteTime[row[[1]]], row[[2]]}, {row, precip}];

prod["timestamp"] = AbsoluteTime[{#, {"Day", "MonthNameShort", "Year", "Hour24", "Minute", "Second"}}] & /@ prod["time"]

The problem I am having is taking each time entry from a row and putting them in one entry in a mathematica table.

(Also, excel screws with dates such as 2012-1-3 and turns them into 1/3/2012, so beware of that)

Thanks again for everything. I'm still pretty new to Mathematica. Your help is much appreciated.

$\endgroup$
  • $\begingroup$ How are you trying to import your file? $\endgroup$ – Peter Roberge Feb 26 '16 at 0:28
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – Michael E2 Feb 26 '16 at 2:16
  • $\begingroup$ I am importing data using the import command, such as data = Import[ "***.csv"]; $\endgroup$ – sanjayr Feb 26 '16 at 15:22
0
$\begingroup$

If dat contains your CSV import (with header row) and "Year" is your first column as in your screenshot then

{AbsoluteTime[#[[1 ;; 5]]], #[[6]]} & /@ Rest@dat

will convert the first 5 columns into a date absolute time and pair it with the "DHI" column entry.

Hope this helps.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.