2
$\begingroup$

I have data in a csv file. The first row has labels, and the first column, too.

Datos = Import["C:\\Users\\jodom\\Desktop\\Data.csv"]

Tha data in the csv file is that:

{{"No", "Vol", "Vel"}, {1, 500, 45}, {2, 700, 67}, {3, 350, 87}, {4, 
123, 23}, {5, 587, 45}, {6, 435, 89}, {7, 896, 65}, {8, 125, 
45}, {9, 476, 27}, {10, 987, 80}}

I put those csv data into a dataset:

B = Dataset[Datos]

You can check it out as an image here,on how it has seen on wolfram after the import: https://drive.google.com/file/d/0B56r_V66BiodQUhUMWNHcHZFOWc/view?usp=sharing

Now I want to convert the first row that has the labels, into a head or label of the dataset, and the first column into a label column, so I can get data from this dataset, like

Dataset[labelrow, labelcolumn]
$\endgroup$
  • 3
    $\begingroup$ can you post your image here instead rather than a google drive link. And maybe reduce the size of the dataset and paste it in the question as well. Right now your post is not very helpful for the reader. $\endgroup$ – Ali Hashmi Feb 28 '17 at 20:29
  • $\begingroup$ for any reason, the mathematica.stackexchange.com webbpage dont let me paste an image.... The dataset is very short... $\endgroup$ – jodomofo Feb 28 '17 at 20:39
  • $\begingroup$ see if the image format is a .PNG which should work. There is a picture tab close to where you wrote the question which should ask you for a picture input $\endgroup$ – Ali Hashmi Feb 28 '17 at 20:41
  • 6
    $\begingroup$ why don't you make up an example with 3/4 rows and columns and just post as text. $\endgroup$ – george2079 Feb 28 '17 at 20:50
  • 1
    $\begingroup$ @jodomofo please delete the other question that you posted. it seems the same thing $\endgroup$ – Ali Hashmi Feb 28 '17 at 21:22
3
$\begingroup$

As the OP,you have a .csv file like:

Then you just use SemanticImport

SemanticImport["Data.csv"]


Of course,if you have a data like:

data = {{"No", "Vol", "Vel"}, {1, 500, 45}, {2, 700, 67}, {3, 350, 
   87}, {4, 123, 23}, {5, 587, 45}, {6, 435, 89}, {7, 896, 65}, {8, 
   125, 45}, {9, 476, 27}, {10, 987, 80}}

You can get a Dataset

SemanticImportString[ExportString[data, "CSV"]]

$\endgroup$
3
$\begingroup$

As of 11.2, I would suggest doing either:

Import["test.csv", "Dataset", "HeaderLines" -> 1]

or

Import["test.csv", "Dataset", "HeaderLines" -> {1, 1}]

enter image description here

$\endgroup$
  • $\begingroup$ Mathematica can't always correctly infer the import format so Import[test.csv, {"CSV","Dataset"}] is a safer option. $\endgroup$ – Theelepel Aug 28 at 14:39
  • $\begingroup$ If the extension .csv is given, it should be able to infer the format. $\endgroup$ – GenericAccountName Sep 5 at 1:20
2
$\begingroup$
data = {{"No", "Vol", "Vel"}, {1, 500, 45}, {2, 700, 67}, {3, 350, 
87}, {4, 123, 23}, {5, 587, 45}, {6, 435, 89}, {7, 896, 65}, {8, 125, 45},
{9, 476, 27}, {10, 987, 80}}


dataset = Dataset[Association@MapThread[(#1 -> <|"Vol" -> #2, "Vel" -> #3 |> &), 
Transpose@Rest@data]]


dataset[1, "Vol"]
(* 500 *)

dataset[1,"Vel"]

(* 45 *)
$\endgroup$
  • $\begingroup$ @jodomofo please see this answer $\endgroup$ – Ali Hashmi Feb 28 '17 at 21:25
  • $\begingroup$ @jodomofo i dont understand what you mean? The answer I posted is clearly a Dataset and you can get the value by row and by column. I dont understand what else you require? $\endgroup$ – Ali Hashmi Feb 28 '17 at 21:37
  • $\begingroup$ yes it is, but it has to look like a table, 'cause it will use in an inform. And, after this, i wil have to operate with each colum... Check what a do in the answer that i published... it has to look like this, and funcion like a dataset. drive.google.com/file/d/0B56r_V66BiodU0lDblRnaHFiZjg/… $\endgroup$ – jodomofo Feb 28 '17 at 21:52
  • $\begingroup$ @jodomofo can you check my code again. Run it. it will look like a table now $\endgroup$ – Ali Hashmi Feb 28 '17 at 21:53
  • $\begingroup$ THAT IS MAN ! THANKS !..... Now, could you check the another question that i posted. Are similar, but not the same, and i wanna the same resutls $\endgroup$ – jodomofo Feb 28 '17 at 22:05
0
$\begingroup$

I have already do something....

data1 = {{"No", "Vol", "Vel"}, {1, 500, 45}, {2, 700, 67}, {3, 350, 87}, {4, 123, 23}, {5, 587, 45}, {6, 435, 89}, {7, 896, 65}, {8, 125, 45}, {9, 476, 27}, {10, 987, 80}} 

data2 = Drop[data1, 1] 
data3 = Dataset[data2] 
data4 = data3[All, <|"No" -> 1, "Vol" -> 2, "Vel" -> 3|>] 

But if you see, i have to delete the first row, to create the labels....there is a way to do that without deleting the first row? another thing....can i do the samething with the rows>

$\endgroup$
0
$\begingroup$
datos =  {{"No", "Vol", "Vel"}, {1, 500, 45}, {2, 700, 67}, {3, 350, 87},
          {4, 123, 23}, {5, 587, 45}, {6, 435, 89}, {7, 896, 65}, {8, 125, 5},
          {9, 476, 27}, {10, 987, 80}};

ds = Dataset[AssociationThread[datos[[2;;,1]]->  
      (AssociationThread[Rest@First@datos->Rest[#]]&/@Rest[datos])]]

Mathematica graphics

ds[2, "Vel"]

67

$\endgroup$
0
$\begingroup$

What you can do is this:

association = AssociationThread[ First @ data, ## ]& /@ data; (* data = Datos *)

dataset = Association /* Dataset @@ (
    association // Query[ All, Lookup[##, "No"] -> Part[##, 2 ;; 3] & ]
)

Mathematica graphics

Then

dataset[ 2, "Vol" ]

700

$\endgroup$
  • $\begingroup$ While you can do this in one step, I find doing it sequentially easier to grasp. $\endgroup$ – gwr Feb 28 '17 at 22:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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