Replace a specific text value in a table with NaN

21 次查看(过去 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
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 CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by