1
$\begingroup$

I am importing simple 0s and 1s array from Excel

myDep = Import[
FileNameJoin[{NotebookDirectory[], "dependencies.xlsx"}], {"Sheets",
"Data"}]

All good

{{1., 0., 0., 1., 0., 0.}, {0., 1., 0., 0., 1., 0.}, {0., 0., 0., 1., 
0., 0.}, {0., 0., 1., 1., 1., 0.}, {1., 0., 1., 0., 0., 1.}, {0., 
0., 0., 1., 0., 0.}}

But I get it imported as Real, and being a newbie I cannot find the way to import is as Integer. Any simple way to import it as Integer numbers? Sorry for such a mundane question.

Thanks a million in advance!

$\endgroup$
  • $\begingroup$ You may be interested in Rationalize $\endgroup$ – MarcoB Mar 13 at 0:55
4
$\begingroup$

Konstantin, Welcome to MSE. If the data values are either 0 or 1, you can use IntegerPart to convert after importing.

IntegerPart[{{1., 0., 0., 1., 0., 0.}, {0., 1., 0., 0., 1., 0.}, {0., 0., 0., 1., 
0., 0.}, {0., 0., 1., 1., 1., 0.}, {1., 0., 1., 0., 0., 1.}, {0., 0., 0., 1., 0., 0.}}]

(* {{1, 0, 0, 1, 0, 0}, {0, 1, 0, 0, 1, 0}, {0, 0, 0, 1, 0, 0}, {0, 0, 1,
   1, 1, 0}, {1, 0, 1, 0, 0, 1}, {0, 0, 0, 1, 0, 0}} *)
$\endgroup$
  • $\begingroup$ It worked perfectly for me myDep = IntegerPart[ Import[FileNameJoin[{NotebookDirectory[], "dependencies.xlsx"}], {"Sheets", "Data"}]] $\endgroup$ – Konstantin Smirnov Mar 13 at 20:48
  • $\begingroup$ That's great. Would you mind accepting my answer. $\endgroup$ – Rohit Namjoshi Mar 13 at 23:21

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.