Replace a specific text value in a table with NaN
13 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I've got a table generated from importing *.csv data.
Some of the values in the table read as 'NOVALUE' and I would like to replace them all by NaN. The table can have various sizes (both in number of columns and rows), so the rule will have to apply to the entire table wherever a 'NOVALUE' is found.
I've tried a few examples with table2array and == but none seems to work in this specific case.
Thanks.
4 件のコメント
dpb
2022 年 6 月 16 日
reatable tries to ascertain the type of the data in each column from parsing the first few records in a file first -- I think it uses detectimportoptions silently. Behavior has continued to change with releases as TMW tries to get more and more clever. If there are nonumeric and/or missing values in those first few records, it will try to guess what to call them -- if there is text it doesn't interpret the text, but just determines it can't be converted to a number unless that is given as the missing value explicitly or is the one (NaN) recognized.
You can set that option for missing values in the import options object as well as telling it which variables are expected to be numeric.
I'm not sure if readmatrix would do better or not; if you've found the solution it's probably not of much more than pedantic interest if it would try to convert to numeric or just interpret all as text automagically.
Image Analyst
2022 年 6 月 27 日
Would the whole column be NOVALUE like you showed, or might some of the other elements have a value.
Would you rather just delete the entire column?
Can you attach one of your CSV files with the paperclip icon after you read this:
採用された回答
Chandrika
2022 年 6 月 27 日
As per my understanding, you want to standardize the missing values in the table. We can do this using 'TreatAsMissing'. You can try using the following code for the same:
data= readtable("Filename.csv","TreatAsMissing","NOVALUE");
Here, 'Filename.csv' refers to the .csv file. As output, all table elements corresponding to "NOVALUE" would get set to NaN.
Hope this helps!
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!