How do I ensure that the number of delimiters on each row are constant when reading a hige csv file
24 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Masood Anzar
le 18 Avr 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
le 18 Avr 2020
You'll still have to either
- Insert a dummy text into blank rows like 'T=nan'
- Or only select the rows that have the delimiter to split
logical addressing/indexing is your friend in such cases.
Réponses (1)
Viren Gupta
le 24 Sep 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.
0 commentaires
Voir également
Catégories
En savoir plus sur Text Files dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!