Effacer les filtres
Effacer les filtres

Replace a specific text value in a table with NaN

10 vues (au cours des 30 derniers jours)
Gabi
Gabi le 16 Juin 2022
Commenté : Image Analyst le 27 Juin 2022
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 commentaires
dpb
dpb le 16 Juin 2022
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 le 27 Juin 2022
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:

Connectez-vous pour commenter.

Réponse acceptée

Chandrika
Chandrika le 27 Juin 2022
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!

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by