Comments (9)
from ya-csv.
Hi, it seems it's just for console output. Writing to another file was fine. This is my code right now. Adding an index to the data seems to give me columns, but what if I want to output the data row by row?
var csv = require('ya-csv');
var fs = require('fs');
var streamout = fs.createWriteStream("output.txt");
// equivalent of csv.createCsvFileReader('data.csv')
var reader = csv.createCsvFileReader('chosen.csv', {
'separator': ',',
'quote': '"',
'escape': '"',
'comment': '',
});
var writer = new csv.CsvWriter(process.stdout);
reader.addListener('data', function(data) {
console.log(data[1]);
streamout.write(JSON.stringify(data[0]));
});
reader.addListener('error', function(e) {
console.error('Oops!');
});
from ya-csv.
from ya-csv.
The console output has been resolved. Now, I'm just wondering how I can selectively output the data row by row in ya-csv using indexes.
var csv = require('ya-csv');
var fs = require('fs');
var streamout = fs.createWriteStream("output.txt");
var reader = csv.createCsvFileReader('myFile.csv', {
'separator': ',',
'quote': '"',
'escape': '"',
'comment': '',
});
var writer = new csv.CsvWriter(process.stdout);
reader.addListener('data', function(data) {
console.log(data[0]);
streamout.write(JSON.stringify(data[0]));
});
reader.addListener('error', function(e) {
console.error('Oops!');
});
My code currently gives me a column of the csv table when I give an index to data such as "data[0]". I'm wondering if there's a ya-csv setting that will make it return rows instead of columns when I give it an index.
For example, if I did data[0], I'd want it to return the first row. What I see right now when I do that is just the first column like below.
Post ID
111519035531887_1898820693468370
111519035531887_1895819030435203
111519035531887_1895099177173855
111519035531887_1893797443970695
111519035531887_1888299321187174
Much Thanks.
from ya-csv.
Ah, I see. The ya-csv is designed to be stream processor with a minimal memory footprint.
Can you help me to understand a bigger picture, why do you prefer to access individual rows? Are you looking for a sort of a random access or is it more like about an ability to skip first N rows easily?
from ya-csv.
I'm doing some social media analytics and each row is essentially a post with a Post ID, and more data about engagement. It's just easier for me to work with and more logical. However, in the process of writing this, I tried.
for (var i =0; i < data.length; i++) {
console.log(data[i]);
}
This gives me each row item by item. Now this confuses me as "data[0]" gives the first column but a for loop with data[i] gives each item in each row.
I guess my question is answered, but I'm just confused now as to why indexing data can switch between rows and columns.
from ya-csv.
Is there any way for ya-csv to know when the order of the 'data' events? I'd like to have something trigger on the last 'data' event of the stream.
from ya-csv.
from ya-csv.
Yup, thanks for the help.
from ya-csv.
Related Issues (20)
- Why do you support only linux or darwin?
- How to catch error HOT 4
- createCsvStreamRead readStream set to undefined?
- Add ability to parse strings HOT 1
- Don't crash when passed a binary file HOT 5
- Last field is set as undefined if it is empty
- publish 0.9.3 to npm HOT 2
- csv files with single quotes fail HOT 1
- Add unicode support! HOT 3
- Option to make escaping optional
- Improvement: Allow periods in column names for property grouping HOT 1
- Writing to a file/stream breaks because writableStream does not have the setEncoding method HOT 2
- How to read a csv file if it's residing in a password protected location? HOT 1
- reader.pause() doesn't seem to work HOT 1
- how to run this project ? HOT 1
- There is no clear way to close a CsvFileWriter HOT 1
- Escaped Quotes at the end of a chunk are incorrectly ignored.
- Support writing object records
- column
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ya-csv.