Mathematica 10 DateObject 到 TimeObject 怪癖
Mathematica 10 DateObject to TimeObject quirk
如果我创建这样的列表:
x = {TimeObject[DateObject[{2015, 09, 9, 01, 01, 01}]],
TimeObject[DateObject[{2000, 01, 1, 09, 09, 09}]]}
(我不能在此处 post 图片,但列表肯定只包含 TimeObjects。)
那么这个工作正常:
x[[1]] < x[[2]]
True
然后,如果我这样导入:
passageInOrOut = Import["/tmp/foo.csv", "DateStringFormat" ->
{"Year", "Month", "Day", "-", "Hour", "Minute", "Second"}];
(文件看起来像这样;日期和时间用“-”分隔)
20150804-174137
20150804-184024
20150804-184629
20150804-202336
20150805-040914
20150805-041904
然后我得到一个 DateObjects 列表,如我所愿(而且我假设时间也在那里。)
后来我只想用时间,所以我试试这个:
TimeObject[passageInOrOut[[6]]] < TimeObject[passageInOrOut[[1]]]
并得到这个(但作为图标和文本):
TimeObject[{Wed 5 Aug 2015}] < TimeObject[{Tue 4 Aug 2015}]
...当我预期 "True" 时,因为我只想比较时钟时间。
我在 "passageInOrOut" 中用我在这里或其他地方找到的每一个 mathematica 咒语打败了狗屎,但除了上述结果或错误消息,我什么也得不到。
由于文件很大,我正在寻找 Map
解决方案或其他解决方案,但首先我需要知道如何转换这些对象。有人可以帮忙吗?
系统信息:
Version:
10.0 for Mac OS X x86 (64-bit) (December 4, 2014)
ReleaseID:
10.0.2.0 (5206630, 2014120404)
PatchLevel:
0
Language:
English
Character Encoding:
UTF-8
System Character Encoding:
UTF-8
Time Zone:
2
Initialization Files Loaded:
file://localhost/Users/xxx/Library/Mathematica/Kernel/init.m
file://localhost/Users/xxx/Library/Mathematica/Paclets/Repository/WolframAlphaClient-2.2.2015060408/Kernel/WolframAlphaClient.m
file://localhost/Users/xxx/Library/Mathematica/ApplicationData/Parallel/Preferences/Preferences.m
恐怕您需要求助于手动解析字符串。试试这个:
passageInOrOut =
DateObject[
Table[ ToExpression@
StringTake[#, p],
{p, {{1, 4}, {5, 6}, {7, 8}, {10, 11}, {12, 13}, {14, 15}}}]
] & /@ Import["/tmp/foo.csv"][[All, 1]]
这似乎也有效,也许更干净一点:
DateObject@
DateList[{#, {"Year", "Month", "Day", "-", "Hour", "Minute",
"Second"}}] & /@ Import["/tmp/foo.csv"][[All, 1]]
如果我创建这样的列表:
x = {TimeObject[DateObject[{2015, 09, 9, 01, 01, 01}]],
TimeObject[DateObject[{2000, 01, 1, 09, 09, 09}]]}
(我不能在此处 post 图片,但列表肯定只包含 TimeObjects。)
那么这个工作正常:
x[[1]] < x[[2]]
True
然后,如果我这样导入:
passageInOrOut = Import["/tmp/foo.csv", "DateStringFormat" ->
{"Year", "Month", "Day", "-", "Hour", "Minute", "Second"}];
(文件看起来像这样;日期和时间用“-”分隔)
20150804-174137
20150804-184024
20150804-184629
20150804-202336
20150805-040914
20150805-041904
然后我得到一个 DateObjects 列表,如我所愿(而且我假设时间也在那里。) 后来我只想用时间,所以我试试这个:
TimeObject[passageInOrOut[[6]]] < TimeObject[passageInOrOut[[1]]]
并得到这个(但作为图标和文本):
TimeObject[{Wed 5 Aug 2015}] < TimeObject[{Tue 4 Aug 2015}]
...当我预期 "True" 时,因为我只想比较时钟时间。
我在 "passageInOrOut" 中用我在这里或其他地方找到的每一个 mathematica 咒语打败了狗屎,但除了上述结果或错误消息,我什么也得不到。
由于文件很大,我正在寻找 Map
解决方案或其他解决方案,但首先我需要知道如何转换这些对象。有人可以帮忙吗?
系统信息:
Version:
10.0 for Mac OS X x86 (64-bit) (December 4, 2014)
ReleaseID:
10.0.2.0 (5206630, 2014120404)
PatchLevel:
0
Language:
English
Character Encoding:
UTF-8
System Character Encoding:
UTF-8
Time Zone:
2
Initialization Files Loaded:
file://localhost/Users/xxx/Library/Mathematica/Kernel/init.m
file://localhost/Users/xxx/Library/Mathematica/Paclets/Repository/WolframAlphaClient-2.2.2015060408/Kernel/WolframAlphaClient.m
file://localhost/Users/xxx/Library/Mathematica/ApplicationData/Parallel/Preferences/Preferences.m
恐怕您需要求助于手动解析字符串。试试这个:
passageInOrOut =
DateObject[
Table[ ToExpression@
StringTake[#, p],
{p, {{1, 4}, {5, 6}, {7, 8}, {10, 11}, {12, 13}, {14, 15}}}]
] & /@ Import["/tmp/foo.csv"][[All, 1]]
这似乎也有效,也许更干净一点:
DateObject@
DateList[{#, {"Year", "Month", "Day", "-", "Hour", "Minute",
"Second"}}] & /@ Import["/tmp/foo.csv"][[All, 1]]