当解析器不是逗号时,如何使用d3解析csv文件 [英] How to parse a csv file with d3 when parser is not the comma

查看:75
本文介绍了当解析器不是逗号时,如何使用d3解析csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理我导入的csv文件,感谢d3。不幸的是,解析器并不总是逗号,我也没有找到解析器在文件架构中的记录位置......无论如何。
现在,我知道我的解析器是分号,然后我试图像这样使用dsv函数

I'm working with csv document that I import thanks to d3. Unfortunatelly, the parser is not allways the comma and I didn't find where the parser is recorded in the file architecture... anyway. Now, I know that my parser is a semicolon, then I've tried to use the dsv function like this


var csvfile = d3.dsv(;,VariableWithcsvFileInside);

var csvfile= d3.dsv(";", VariableWithcsvFileInside);

console.log(data); 返回:


function e(n,e,i){arguments.length< 3&& (i = e,e = null); var
a = Cn(n,t,null == e?r:u(e),i); return a.row = function(n){return
arguments.length?a.response(null ==(e = n)?r:u(n)):e},a}

function e(n,e,i){arguments.length<3&&(i=e,e=null);var a=Cn(n,t,null==e?r:u(e),i);return a.row=function(n){return arguments.length?a.response(null==(e=n)?r:u(n)):e},a}

是否有我必须导入的脚本或我做错了什么?
感谢您的回复。

Is there a script that I have to import or something I do wrong? Thanks for anwering.

PS: var csvfile = d3.csv.parse(VariableWithcsvFileInside); 工作...

推荐答案

很难说出发生了什么,因为你没有包含加载和解析数据的代码一个网址,但这是它应该如何工作:

Hard to tell what's happening, because you didn't include the code that loads and parses the data from a url, but this is how it should work:

// ssv is "Semicolon Separated Values" parser
var ssv = d3.dsv(";", "text/plain");

// Load and (later, asynchronously) parse the data
ssv(url, function(data) {
  console.log(data); // should log an array of parsed values
});

如果数据已经加载并且只需要解析,则第二行变为:

If the data is already loaded and just needs to be parsed then the 2nd line becomes:

var data = ssv.parse(stringOfDataThatWasAlreadyLoaded);
console.log(data); // should log an array of parsed values

这篇关于当解析器不是逗号时,如何使用d3解析csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆