3
$\begingroup$

How can I import only the 2nd and 5th elements (numbers, located in the 2nd and 5th columns) from all n raws of a data file (.xlxx) that contains both numbers and text. Imported data be inserted into a constant array. Thanks

$\endgroup$
1

1 Answer 1

3
$\begingroup$

Even though I don't see it in the documentation, you can use All when specifying what elements you want to import.

So for an example Excel spreadsheet:

enter image description here

We can import the 2nd and 5th elements from every row on the first sheet as such:

Import["pathtoxlsx.xlsx", {"Data", 1, All, {2, 5}}]

{{0.612328, 0.325049}, {0.909502, 0.206016}, {0.531286, 0.267417}, {0.441283, 0.714645}, {0.369051, 0.581077}, {0.421404, 0.598902}, {0.859646, 0.817586}, {0.477507, 0.820588}, {0.915968, 0.559369}, {0.962673, 0.944758}, {0.803255, 0.166438}, {0.483266, 0.661242}, {0.499209, 0.159238}, {0.554271, 0.593598}, {0.0609692, 0.528343}, {0.046578, 0.922516}, {0.715221, 0.00963152}, {0.134301, 0.448886}, {0.0765122, 0.701141}, {0.130223, 0.132252}, {0.474112, 0.0138053}, {0.342081, 0.125728}, {0.274643, 0.0554139}}

$\endgroup$
7
  • $\begingroup$ Truly brilliant. All the more so since the Documentation for Import is so short. $\endgroup$
    – eldo
    Commented Sep 15, 2014 at 18:10
  • $\begingroup$ nice. does this perform any different vs Import[...][[1,All,{2,3}]] $\endgroup$
    – george2079
    Commented Sep 16, 2014 at 11:44
  • $\begingroup$ Just checked that, it is in fact faster to import the whole works and take what you need afterward. $\endgroup$
    – george2079
    Commented Sep 16, 2014 at 18:31
  • $\begingroup$ Thanks Kale and George, I am really a novice. Just starting my first steps, so sorry for the really simple questions. Did like Kale recommended and got as out :out[2]= import["desktop/ipxi/4136928.xlsx", {"data", 1, All, {2, 4}}] How can I actually se the results like in Kale's example? $\endgroup$
    – Assaf Thon
    Commented Sep 21, 2014 at 15:46
  • $\begingroup$ Assaf -> Open it in excel $\endgroup$ Commented Apr 24, 2017 at 17:23

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.