필터 지우기
필터 지우기

Replace a specific text value in a table with NaN

조회 수: 10 (최근 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 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