Group Abstract Group Abstract

Message Boards Message Boards

0
|
3.3K Views
|
5 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to replace "" with blank?

Posted 3 years ago

Hello, In my Excel file, some results are ="" So, when I import it to Mathematica, these ="" will show blank. But When I calculate with, these ="" can calculate! So how can I replace "" with blank in Mathematica

d=Dataset@{<|"a" -> "", "b" -> 0.869667, "c" -> 0.069534|>, <|"a" -> 0.906971, 
  "b" -> 0.614134, "c" -> 0.943003|>, <|"a" -> 0.46762, 
  "b" -> 0.619722, "c" -> 0.237383|>, <|"a" -> 0.0532133, "b" -> "", 
  "c" -> 0.160852|>, <|"a" -> 0.968014, "b" -> 0.609222, 
  "c" -> 0.522014|>, <|"a" -> 0.331874, "b" -> 0.0132003, 
  "c" -> 0.175512|>, <|"a" -> 0.274197, "b" -> 0.892181, 
  "c" -> 0.560612|>, <|"a" -> 0.20482, "b" -> 0.503641, 
  "c" -> 0.456528|>, <|"a" -> 0.607325, "b" -> 0.972514, 
  "c" -> 0.468308|>, <|"a" -> 0.726064, "b" -> 0.976656, 
  "c" -> 0.166471|>, <|"a" -> 0.576529, "b" -> 0.418368, 
  "c" -> 0.422449|>, <|"a" -> 0.935738, "b" -> 0.730028, 
  "c" -> 0.518465|>, <|"a" -> 0.167812, "b" -> 0.49489, 
  "c" -> 0.18876|>, <|"a" -> 0.487007, "b" -> 0.632814, 
  "c" -> 0.607625|>, <|"a" -> 0.542796, "b" -> 0.818752, 
  "c" -> 0.915069|>, <|"a" -> 0.21409, "b" -> 0.443561, 
  "c" -> 0.923162|>};
g = 5*(Normal[d[All, "a"]][[1]])

The result is 5. I want to this "" can't be calculated. Thanks.

POSTED BY: Zhenyu Zeng
5 Replies
Posted 3 years ago
Posted 3 years ago

Hello, Thanks for your reply. Your answer is certainly what I wanted. Have a nice day!

POSTED BY: Zhenyu Zeng
Posted 3 years ago

Hello, Thanks for your reply. I find documents in Mathematica, but I can't find detailed information about Missing. I feel that you know more than documents about Missing. Of course, I will use Missing in the future when I want to keep something empty.

POSTED BY: Zhenyu Zeng

Hi

First there is a syntax error. Either there is a missing "@" or a missing pair of brackets "[ ]". The result you get is not 5 it just looks like a five actually it is 5 * "" which is not a numeric value.

Next you need to decide which value to use when replacing "" e.g. 0.

Maybe this is what you are looking for:

In[9]:= d = 
  Dataset@{<|"a" -> "", "b" -> 0.869667, "c" -> 0.069534|>, <|
      "a" -> 0.906971, "b" -> 0.614134, "c" -> 0.943003|>, <|
      "a" -> 0.46762, "b" -> 0.619722, "c" -> 0.237383|>, <|
      "a" -> 0.0532133, "b" -> "", "c" -> 0.160852|>, <|
      "a" -> 0.968014, "b" -> 0.609222, "c" -> 0.522014|>, <|
      "a" -> 0.331874, "b" -> 0.0132003, "c" -> 0.175512|>, <|
      "a" -> 0.274197, "b" -> 0.892181, "c" -> 0.560612|>, <|
      "a" -> 0.20482, "b" -> 0.503641, "c" -> 0.456528|>, <|
      "a" -> 0.607325, "b" -> 0.972514, "c" -> 0.468308|>, <|
      "a" -> 0.726064, "b" -> 0.976656, "c" -> 0.166471|>, <|
      "a" -> 0.576529, "b" -> 0.418368, "c" -> 0.422449|>, <|
      "a" -> 0.935738, "b" -> 0.730028, "c" -> 0.518465|>, <|
      "a" -> 0.167812, "b" -> 0.49489, "c" -> 0.18876|>, <|
      "a" -> 0.487007, "b" -> 0.632814, "c" -> 0.607625|>, <|
      "a" -> 0.542796, "b" -> 0.818752, "c" -> 0.915069|>, <|
      "a" -> 0.21409, "b" -> 0.443561, "c" -> 0.923162|>} /. "" -> 0;
g = 5*(Normal[d[All, "a"]][[1]])

Out[10]= 0

Robert

POSTED BY: Robert Nowak
Posted 3 years ago
  1. I assume that the missing [] in your Dataset is a copy-paste error of some kind.
  2. The result isn't 5. The result is Times[5, ""].
  3. What do you want your result to be? Just saying that you want "" to not be calculated doesn't help, since it isn't calculated (I'm assuming that when you say "calcluated" you mean something like "treated numerically").
  4. Once you decide what the semantics of "" should be you can use ReplaceAll. Let's say you want "" to become Null:

    d /. "" -> Null
    

Or maybe you do want everthing to be numeric:

    d /. "" -> 0

Or maybe you want to be very specific about what "" means in your context:

    d /. "" -> Missing["Nonexistent"]

Be aware that none of these actually change the value of d. You can either store these in a new variable

d2 = d /. "" -> Missing["Nonexistent"]

or update d itself

d = d /. "" -> Missing["Nonexistent"]
POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard