admin管理员组文章数量:1308570
Say I have a sample file sample.csv:
row,col,value
1,1,2
1,2,3
1,3,NA
When reading data in d3 you do something like:
d3.csv("sample.csv", function(data) {
data.forEach(function(d) {
d.value = +d.value;
});
However, for the NA value +d.value will return NaN. How can I exclude NaN values from my data. i.e. read the data, and only take rows which have a number value
Thanks!
Say I have a sample file sample.csv:
row,col,value
1,1,2
1,2,3
1,3,NA
When reading data in d3 you do something like:
d3.csv("sample.csv", function(data) {
data.forEach(function(d) {
d.value = +d.value;
});
However, for the NA value +d.value will return NaN. How can I exclude NaN values from my data. i.e. read the data, and only take rows which have a number value
Thanks!
Share Improve this question asked Oct 16, 2012 at 19:38 Omar WagihOmar Wagih 8,7447 gold badges64 silver badges75 bronze badges1 Answer
Reset to default 9You can call isNaN
on the data before you try to add it:
d3.csv('sample.csv', function(data) {
data = data.filter(function(d){
if(isNaN(d.value)){
return false;
}
d.value = parseInt(d.value, 10);
return true;
});
});
This assumes your numbers will all be base-10 integers.
本文标签: javascriptRemoving rows when reading data D3Stack Overflow
版权声明:本文标题:javascript - Removing rows when reading data D3 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741783485a2397446.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论