1
$\begingroup$

I have imported into Mathematica notebook data from TXT file. I would like to make it as a Table afterwards, so I can do some calculations. I wrote:

I wrote:

dat = Import["PirmaisPikis.txt"]

It gives out:

1   7
2   7
3   2
4   2
5   2
6   3
7   2
8   3
9   2
10  2
11  3
12  2

If I write:

dat = Import["PirmaisPikis.txt"];
fabri = Table[{dat[[i, 1]], dat[[i, 2]]}, {i, 600}]

It gives me out ( and does it 3 times):

Part::partd: "Part specification" 1 7
2   7
3   2
4   2
5   2
6   3
7   2
8   3
9   2
10  2
11  3
12  2

Same thing If I write:

dat = Import["PirmaisPikis.txt"];
fabri = Table[{dat[[i, 1]], {i, 1, Length[dat]}]

If I write:

dat = Import["PirmaisPikis.txt"]; 
fabri = Table[{dat[[i, 1]], dat[[i,2]]}, {i, 1, Length[dat]}]

It gives me out nothing {} What is the problem?

(You can import with Import["https://pastebin.com/raw/w9ys8Rfd"].)

$\endgroup$
  • $\begingroup$ Without access to PirmaisPikis.txt it is difficult to say. Can you show a small example of the dat after importing or share the text file? $\endgroup$ – Jack LaVigne Oct 26 '17 at 14:50
  • $\begingroup$ We need to see the all of the curly brackets. Edit and add to the question, not the comment $\endgroup$ – Jack LaVigne Oct 26 '17 at 14:55
  • $\begingroup$ You may also put the text file in a dropbox or pastebin for downloading. $\endgroup$ – Jack LaVigne Oct 26 '17 at 14:57
  • $\begingroup$ Post the output of dat[[1;;5]] if your data is too large. You can try fabri = dat[[All,1;;2]]. $\endgroup$ – Sumit Oct 26 '17 at 14:58
  • $\begingroup$ dat2=ImportString[dat, "Table"] ? $\endgroup$ – Ruud3.1415 Oct 26 '17 at 15:00
4
$\begingroup$

The problem is that Mathematica defaultly imports the file as a single string, not a table. You have to import the table form the imported string:

dat = ImportString[Import["pirmaispikis.txt"], 
   "Table"]; 

or import the file as a table by Import["pirmaispikis.txt","Table"]

gives the table you want and

fabri=dat;
$\endgroup$

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.