I am trying to read a csv file from 4th row, in my csv file first 3 rows contains some meta data in column1. But the actual number of columns in csv is 6.
I am getting data as undefined. Also If I am removing the args of parse, I am getting error Error: Invalid Record Length: expect 1, got 6 on line 4. Please guide!
The error message “Error: Invalid Record Length: expect 1, got 6 on line 4” indicates that the parse function is expecting a single value per line, but it’s encountering 6 values on line 4. This is likely due to the fact that you’re skipping the first 3 rows, which contain metadata, and the actual data starts on line 4.
Here’s a corrected version of your code that should read the CSV file from the 4th row and handle the 6 columns correctly:
from_line: 4: This option tells the parse function to start reading from the 4th row.
columns: true: This option tells the parse function to create an object for each row, using the column names as keys and the corresponding values as values. This will handle the 6 columns correctly.
With these changes, the data variable will contain an array of objects, each representing a row in the CSV file, starting from the 4th row. You can access the data using the column names: