0

I looked at their API but didn't have any success with it.

I'm trying to parse some csv files that are being sent to the client when he enters the server.

I tried this code:

// Parse local CSV file
Papa.parse("data/premier league/14-15s.csv", {
    complete: function(results) {
        console.log("Finished:", results.data);
    }
});

which didn't work. It gives the following output:

Finished: [Array[1]]0: Array[1]0: "data/premier league/14-15s.csv"length: 1__proto__: Array[0]length: 1__proto__: Array[0]concat: function concat() { [native code] }constructor: function Array() { [native code] }entries: function entries() { [native code] }every: function every() { [native code] }filter: function filter() { [native code] }forEach: function forEach() { [native code] }indexOf: function indexOf() { [native code] }join: function join() { [native code] }keys: function keys() { [native code] }lastIndexOf: function lastIndexOf() { [native code] }length: 0map: function map() { [native code] }pop: function pop() { [native code] }push: function push() { [native code] }reduce: function reduce() { [native code] }reduceRight: function reduceRight() { [native code] }reverse: function reverse() { [native code] }shift: function shift() { [native code] }slice: function slice() { [native code] }some: function some() { [native code] }sort: function sort() { [native code] }splice: function splice() { [native code] }toLocaleString: function toLocaleString() { [native code] }toString: function toString() { [native code] }unshift: function unshift() { [native code] }Symbol(Symbol.iterator): function ArrayValues() { [native code] }Symbol(Symbol.unscopables): Object__proto__: Object

where is the csv??

2 Answers 2

1

Although this question was posted 5 months ago, I believe I've been having a similar problem, and I just solved it, so I thought I'd share what I THINK is the solution, in case other beginners, like myself stumble across in search of an answer.

It looks to me like you're trying to have papa parse parse through an csv file on your machine through a path. I believe that this would mean you're parsing a remote file, which on the papa parse website looks like:

Papa.parse(url, {
    download: true,
    // rest of config...
});

So it looks to me like you're just missing the second argument where download: true. It says in their documentation that url can also be a path - like the one you have. Again, I'm not super confident in my answer because I only started coding about 7 weeks ago, but hopefully that might help someone else who stumbles onto this post in confusion!

Sign up to request clarification or add additional context in comments.

Comments

0

You're parsing a string with the contents data/premier league/14-15s.csv - not a local CSV file. Take another look at the docs. To parse a local CSV file, you must pass in a File object which is obtained from a <input type="file"> element.

7 Comments

How would I create a File object with that directory?
By doing what I said - create an input element of type file. The user has to select the file(s) in order for the browser to give you access to them.
Am I supposed to change the string to <input type=string> ?
No. I recommend reading up on how to use input elements on your web page. Then follow the link I posted about File objects where you can learn how to get those from the DOM.
Why do I need to include HTML input elements in order to parse a file?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.