Created
June 23, 2015 20:57
-
-
Save mikeatlas/0ca2d987391ba03f9eed to your computer and use it in GitHub Desktop.
some simple in/out CSV parsing/fixing
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
// Fix up our CSV data | |
var fs = require('fs'); | |
var csv = require('csv'); | |
var allWPIsInputFs = fs.createReadStream('./input-data/all-wpi-lat-long.csv'); | |
var mappedWPIsInputFs = fs.createReadStream('./input-data/mapped-wpi-lat-lons.csv'); | |
var output = fs.createWriteStream('./input-data/all-wpi-lat-long_trim.csv'); | |
var parser = csv.parse({delimiter: ','}); | |
parser.on('readable', function(){ | |
while(record = parser.read()){ | |
output.write(record[0] + ",\"" + record[1].toProperCase() + | |
"\"," + | |
Number(record[2]).toFixed(6).toString() + "," + | |
Number(record[3]).toFixed(6).toString() + | |
"\n"); | |
} | |
}); | |
allWPIsInputFs.pipe(parser).pipe(output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment