Readtable reads numerical row as strings
Show older comments
When using the function
tr_data = readtable(...)
on the train.csv file I have attached here, the last column (Weightfirst) is seen as strings. However when creating this CSV (with python) I have made sure that only numerical data was contained in it, I have double checked to make sure and I can confirm that the column only contains float values (and NaNs).
On top of that, when reading test.csv, which I have also attached here, the column is correctly seen as numerical. But both test.csv and train.csv come from the same code, the only difference being in the data those csvs contain.
I have been looking for hours to try and understand what was different about those two csv, but I can't find anything, I have no idea why train.csv is not being read correctly.
I have tried running the element wise function
if ischar(x)
o = str2double(x);
else
o = x;
end
But the column still contains only strings. I have read some similar problems and the solution was to add the characters which caused problems to "TreatAsEmpty", the problem is I'm not even sure any particular character is causing the problem here.
Any insights on what's going on here?
4 Comments
My suspicion is that the difference is on line two: that particular column is empty so possibly for some reason readtable treats that entire column as char. Try entering (by hand) one numeric value in the last column of row two of train.csv, and let us know what happens... then hopefully we can figure out a solution.
Luca Rizzello
on 11 Jun 2018
Luca Rizzello
on 11 Jun 2018
Edited: Luca Rizzello
on 11 Jun 2018
Accepted Answer
More Answers (0)
Categories
Find more on Variables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!