Created
October 10, 2012 19:19
-
-
Save robdodson/3867807 to your computer and use it in GitHub Desktop.
Getting column names with d3.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
/* | |
Example cars.csv: | |
Year,Make,Model,Length | |
1997,Ford,E350,2.34 | |
2000,Mercury,Cougar,2.38 | |
*/ | |
d3.csv('cars.csv', function(csv) { | |
csv.forEach(function(row) { | |
console.log(Object.keys(row)); | |
}); | |
}); | |
/* | |
For each row outputs: ["Year", "Make", "Model", "Length"] | |
*/ | |
</script> |
@hatemhosny your method wasn't working. Here is the correct way to read in a csv file and get the column names:
d3.csv('csv/analytic_data2010.csv').then(function (data) { console.log(data.columns); });
Here is the link to the source: https://github.com/d3/d3-fetch/blob/master/README.md#installing. The only thing I added is the .columns.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/d3/d3-dsv#dsv_parse