Readtable reads numerical row as strings
이전 댓글 표시
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
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
2018년 6월 11일
Luca Rizzello
2018년 6월 11일
편집: Luca Rizzello
2018년 6월 11일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Variables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!