【发布时间】:2020-07-21 19:22:48
【问题描述】:
有没有人知道如何解析这样的数据?
2020-07-02 15:27:05.000000,73.78999328613281
2020-07-02 15:42:10.000000,73.9699935913086
2020-07-02 15:57:16.000000,73.70999145507812
2020-07-02 16:12:21.000000,73.90999603271484
2020-07-02 16:27:26.000000,74.27999114990234
2020-07-02 16:42:32.000000,74.07999420166016
2020-07-02 16:57:37.000000,73.99999237060547
2020-07-02 17:12:42.000000,74.2699966430664
2020-07-02 17:27:47.000000,74.28999328613281
2020-07-02 17:42:52.000000,74.14999389648438
2020-07-02 17:57:56.000000,73.9699935913086
我正在尝试使用 d3 库来试验 timeParse 和 utcParse。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!-- Load d3.js -->
<script src="https://d3js.org/d3.v4.js"></script>
<!-- Create a div where the graph will take place -->
<div id="my_dataviz"></div>
</head>
<script>
time = d3.timeParse("%m/%d/%Y %H:%M:%S %p")("1/2/2014 8:22:05 AM");
console.log(time);
time2 = d3.utcParse("%Y-%m-%dT %H:%M:%S")("2020-07-02 17:57:56.000000");
console.log(time2);
</script>
</body>
</html>
I am trying to follow the d3 documentation,但是当通过开发控制台查看 html 文件时,utcParse attempt 将返回 null。有人有什么建议吗?
Date Thu Jan 02 2014 08:22:05 GMT-0600 (Central Standard Time)
test.html:17:11
null
【问题讨论】:
-
来自 d3 文档,
Parsing is strict: if the specified string does not exactly match the associated specifier, this method returns null.而且您的数据在日期和时间部分之间不包含 T,但您的说明符有一个 T。尝试删除 T。 -
删除
T仍然会产生 null。我可能会尝试找到一种方法来操作数据,使其不是 UTC 格式 -
您对 Python 和 pandas 有什么技巧可以操作
Date格式吗?什么日期和时间格式包含T?
标签: javascript d3.js web-frontend