Use SemanticImport on column with UnixTime in miliseconds
What about converting them afterwards?
SemanticImport[
"filename.csv", <|"timestamp" -> "Integer", "value" -> "Real"|>
][
All, {"timestamp" -> (FromUnixTime[#/1000] &)}
]
As Kuba and Peter already found out the problem is that the timestamps are in milliseconds instead of seconds which makes necessary a corresponding correction.
Similar to Kuba's answer you can also directly use a Function
instead of a string in the column specifications for SemanticImport
, e.g.:
SemanticImport[
"filename.csv", <|
"timestamp" -> (FromUnixTime[Internal`StringToDouble@#/1000] &),
"value" -> "Real"
|>
]
Honestly after consulting the documentation I'm not sure whether I should consider that to be documented or not, it probably is not...
While this also works with SemanticImportString
in general there are cases which don't work, e.g. the following example fails for me (MMA on Windows 7):
str = "timestamp value
1483525115395 6.2315826416015625
1483525115495 6.2315826416015625
1483525115596 6.2315826416015625
1483525115698 6.2315826416015625
1483525115762 6.56842041015625
1483525115800 6.56842041015625
1483525115860 6.399993896484375
1483525115902 6.399993896484375
1483525116005 6.399993896484375";
SemanticImportString[str, <|
"timestamp" -> (FromUnixTime[Internal`StringToDouble@#/1000] &),
"value" -> Internal`StringToDouble|>]
on the other hand this (and some other similar cases) works as expected:
SemanticImportString[str, <|
"timestamp" -> (FromUnixTime[Internal`StringToDouble@#/1000] &),
"value" -> "Real"|>]