3
$\begingroup$

I am loading a dataset into Mathematica and the format is always recognized as an Atom String:

DS[All, 4]

[1]: https://i.sstatic.net/VPX6d.png

AtomQ[DS[All, 4]]
(* True *)

In this format I cannot analyze the data. Unfortunately, I cannot modify the data before I load it into Mathematica.

Any help is welcome.

I tried ToString (horrible outcome):

In[111]:= ToString[DS[All, 4]]

Out[111]= "Dataset[{23,8, 24,9, 25,7, 23,8, 23,4, 23,8, 25,9, 24,4, \
24,9, 25,4, 25,3, 26,1, 25,5, 24,0, 23,9, 26,2, 24,6, 26,6, 26,4, \
26,2}, TypeSystem`Vector[TypeSystem`Atom[String], 20], <|Origin -> \
HoldComplete[Query[All, 4][Dataset`DatasetHandle[37310558245194]]], \
ID -> 52209799798783|>]"

and Replace

DS[All, 4] /. "," -> "."

but both did not work.

$\endgroup$
8
  • 1
    $\begingroup$ Dataset objects are always atoms, so this part is not the issue. Unless you have more specific information (e.g. part of the file you're trying to import & the code you're using to do so), it will be very difficult to help you. $\endgroup$
    – Lukas Lang
    Commented Aug 15, 2019 at 12:56
  • $\begingroup$ So it is not possible to modify the data (in Atom form) once it it designated as a dataset? $\endgroup$ Commented Aug 15, 2019 at 13:06
  • $\begingroup$ you can modify them. Take a look at the (quite extensive) documentation of Dataset. If you tell us in more detail what you're after, we can point you in a more specific direction $\endgroup$
    – Lukas Lang
    Commented Aug 15, 2019 at 13:18
  • 2
    $\begingroup$ Can you show how you import the data? While it's possible to fix them afterwards, it might be significantly cleaner and faster to import it properly in the first place $\endgroup$
    – Lukas Lang
    Commented Aug 15, 2019 at 13:37
  • 2
    $\begingroup$ @PhilippeDufour - anytime you have something in the form of a Dataset, you can use Normal to convert it to a useful form. What do you see when you evaluate Normal[DS]? $\endgroup$
    – Jason B.
    Commented Aug 15, 2019 at 14:01

1 Answer 1

3
$\begingroup$
ds = Dataset[{"23,8", "24,9", "25,7", "23,8", "23,4", "23,8", "25,9", 
   "24,4", "24,9", "25,4", "25,3", "26,1", "25,5", "24,0", "23,9", 
   "26,2", "24,6", "26,6", "26,4", "26,2"}, 
  TypeSystem`Vector[TypeSystem`Atom[String], 20], <|
   Origin -> HoldComplete[
     Query[All, 4][Dataset`DatasetHandle[37310558245194]]], 
   ID -> 52209799798783|>];

ds2 = ds[Interpreter["Number", NumberPoint -> ","]]

enter image description here

Total[ds2]
(*  500.8  *)

Mean[ds2]
(*  25.04  *)

Probably the dataset could have been imported as a list of numbers instead of strings to begin with, but if not, then you can convert as above.

$\endgroup$
2
  • $\begingroup$ Perfect, thanks a lot! That worked. $\endgroup$ Commented Aug 16, 2019 at 11:48
  • $\begingroup$ @PhilippeDufour You're welcome. $\endgroup$
    – Michael E2
    Commented Aug 16, 2019 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.