How do I ensure that the number of delimiters on each row are constant when reading a hige csv file

23 visualizzazioni (ultimi 30 giorni)
I have a huge csv file using comma. Using the readtable function, I keep getting the error message: ''All lines of a text file must have the same number of delimiters.''.
rawdata = readtable(filename, 'Delimiter', ',');
How can I ensure that each row has the same number of delimiters?
  4 Commenti
Masood Anzar
Masood Anzar il 18 Apr 2020
How to handle if the any row of column is blank
I have a table containing data like 't=1139692479071' in each row of first column.
But some of the row are blank. I want to split the data using '=' as separator.
When I run this command ===> split(T{:,1},'=')
This error is coming : Element 2687 of the text contains 0 delimiters while the previous elements have 3.
All elements must contain the same number of delimiters.
Please advice me how to apply delimiter if the data have blank elements. I cannot remove blank rows as there is data in other columns also.
dpb
dpb il 18 Apr 2020
You'll still have to either
  1. Insert a dummy text into blank rows like 'T=nan'
  2. Or only select the rows that have the delimiter to split
logical addressing/indexing is your friend in such cases.

Accedi per commentare.

Risposte (1)

Viren Gupta
Viren Gupta il 24 Set 2018
Making sure that each line of the input file has same number of delimiters is what the person who created this file has to do. You can only check if each line of the file has same number of delimiters. For this, you can use 'fgets()' function which gives you a string and then use 'strsplit' function based on ',' as your delimiter and then check the size of the cell array returned. If all such cells have same size, then each row has same number of delimiters else not.

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by