-2
$\begingroup$

As you can see from the picture, it's a txt. file, and when I use Import, lot's of different type of data stored in one column, I want to devide them into different columns. For example: the 1st column is the "USAF" and the numbers below it, the 2nd is the "WBAN" and the numbers below it, the 3rd is the "STATION NAME" and the names below it... I've tried to store the txt. file into csv. and file, but it still showed in this way.

enter image description here

enter image description here

$\endgroup$
4
  • 1
    $\begingroup$ Share your original data with us. We can't give good suggestions without trying something out ourselves. What are the record separators in the text file? Have you tried importing as "Table" rather than "Data"? $\endgroup$ – MarcoB Mar 29 at 14:40
  • $\begingroup$ I couldn't find the hyperlink of the file. And the separators in the text file should be space. $\endgroup$ – Liming Zhou Mar 29 at 15:05
  • $\begingroup$ Try something like Import["yourfilename", "Table", "HeaderLines" -> 1, "IgnoreEmptyLines" -> True, FieldSeparators -> {" ", "\t"}] // Dataset instead like MarcoB suggests. $\endgroup$ – Carl Lange Mar 29 at 18:16
  • $\begingroup$ Thank you, but that doesn't devide the dataset into more columns. And I have already found the source file that is divided into columns. I will abandon the reference to this file and use the new one. $\endgroup$ – Liming Zhou Mar 30 at 9:55
0
$\begingroup$

You can try the function SemanticImport. Look at the options this function has to adapt to your particular case: https://reference.wolfram.com/language/ref/SemanticImport.html

$\endgroup$
2
  • 1
    $\begingroup$ You might wish to demonstrate. $\endgroup$ – bbgodfrey Mar 29 at 22:21
  • 1
    $\begingroup$ I flagged this post as "non-answer". $\endgroup$ – Anton Antonov Mar 30 at 6:50
0
$\begingroup$

You can use the resource function ImportCSVToDataset:

ResourceFunction["ImportCSVToDataset"]["~/Downloads/noaa-stations.txt", "TSV"]

Here is an example with a text file data similar to the one in the images you posted:

enter image description here

$\endgroup$
1
  • $\begingroup$ Yeah, thank you, that might be a useful way, but I forgot the hyperlink of the file. Fortunately, I got the new source with different columns. And I will use that one. $\endgroup$ – Liming Zhou Mar 30 at 10:00

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.