Why does Readtable return NaN for values greater than 1000?
Show older comments
I was working with a dataset that contains the annual GDP of all countries in billion USD. However, when importing the dataset with readtable, the corresponding table omits all data points that are greater than 1000.
fileName2 = 'GDP by Country 1999-2022.csv';
GDP = readtable(fileName2);
The following is the original CSV data (see Canada)

Whereas the table GDP that readtable produces is as below

Is there a reason for this happening?
4 Comments
Daniel
on 27 Nov 2023
What is the comma character , being used in more-than-a-thousand numbers to separate the thousands from hundreds? They should not be regular commas since your original file is a CSV. Maybe the character is the problem causing Matlab to not recognize these numbers.
Kevin
on 27 Nov 2023
Stephen23
on 27 Nov 2023
"the authors used double-quotes for any number greater than 1000"
Ugh.
"Any suggestions on how to convert these strings to double while importing?"
Upload a sample data file by clicking the paperclip button.
Kevin
on 27 Nov 2023
Accepted Answer
More Answers (1)
Walter Roberson
on 27 Nov 2023
GDP = readtable(fileName2, "ThousandsSeparator",",");
Categories
Find more on Cell Arrays 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!