フィルターのクリア

Replace a specific text value in a table with NaN

20 ビュー (過去 30 日間)
Gabi
Gabi 2022 年 6 月 16 日
コメント済み: Image Analyst 2022 年 6 月 27 日
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
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
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
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 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by