Skip to content
Advertisement

How do I count word occurrences in a csv file?

I have a CSV file that I need to read and display the number of occurrences of each word, the application should only count words that have more than one letter and not alphanumerical also turned to lowercase.

This is what I have right now and I’m stuck at this and have no ideas where to go from this.

JavaScript

I am trying to read the second index in the array list of the csv, which is line[1] , This is where the text of the document is located.

I have replaced all punctuation with spaces and trimmed it, also if there are more than 2 spaces I have replaced those with 1 and made it lowercase.

The output I am trying to achieve is:

JavaScript

EDIT: This is an example of my input file.

JavaScript

Advertisement

Answer

Your solution does not look that bad. But for initialization i would replace

JavaScript

with

JavaScript

Since I am mising your Input file i created a dummy that works fine.

JavaScript

Are you sure that accessing line[1] in an loop while iteration is correct? The correct reading of the input seems to be the problem for me. Without seeing your CSV file i however cant help you any further.

EDIT:

with the provided csv data an adjustemt to your Code like this would solve your Problem

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement