Message Boards Message Boards

0
|
25946 Views
|
5 Replies
|
5 Total Likes
View groups...
Share
Share this post:

How can I get Mathematica's Import command to work?

Posted 11 years ago
I'm using Mathematica v9 Home Edition on an iMac. I've tried
data = Import["Desktop:sampledata.xlsx", {"Data", 1}]
and
data = Import["sampledata.xlsx", Path->"Desktop:",{"Data", 1}]
as well as other variants including the name of my iMac followed by a single colon or a double colon at the beginning of the path or the filename when I don't use a path.

No matter which way I go, Mathematica always gives me
Import::nffil: File not found during Import.
Another question, which is possibly more a Mac question than a Mathematica question, is how I can get the complete file specification without typing all the characters myself.  Surely there's some Finder shortcut that will give me that character string after I click on the file name.
POSTED BY: Harry Pool
5 Replies
A solution for mac :
ClearAll["Global`*"]
data = Import[SystemDialogInput["FileOpen"], "XLS"];
You can choose your file in a window, and the data are imported in data
POSTED BY: André Dauphiné
You can also use SetDirectory[] like this:

SetDirectory["/Users/username/Desktop"];


Now Import[] will check this directory for the named file.
POSTED BY: Joshua Martell
Posted 11 years ago
Thanks, Markus.  When I select the file in the Finder and use "cmd+i", I get an Info box.  The box does have a "Name & Extension" component containing the text string "sampledata.xlsx" which I can copy and paste.  The Info box also has a "General" component with other information about the file including "Where: /Users/store/Desktop" and I also can copy Where's text string.

In Mathematica, I tried
  data = Import["/Users/store/Desktop/sampledata.xlsx", {"Data", 1}]
which worked perfectly.  I also tried
  data = Import["sampledata.xlsx",
Path -> "/Users/store/Desktop", {"Data", 1}]
giving me "Import::argt: Import called with 3 arguments; 1 or 2 arguments are expected."  I got the same error with
  data = Import["sampledata.xlsx",
Path -> "/Users/store/Desktop/", {"Data", 1}]
 
I'd prefer to use the Path option, but I obviously don't know the syntax Mathematica requires for a path specification.
POSTED BY: Harry Pool
Posted 11 years ago
Dear Harry

As described in the Mathematica help under "Import" you can define a filename including file path and if needed an additional option to import the specified elements from the file.

If you want to define path and filename independent which is sometimes useful you can do it like this:
myPathName = "/Users/iMacName/Desktop/";
data = Import[FileNameJoin[{myPathName, "sampledata.xlsx"}], {"Data", 1}]

It might be also useful to take a look in the help to “Directories & Directory Operations”

I hope that works for you.

Regards, Markus
POSTED BY: Markus Linder
Posted 11 years ago
Hi Harry

Try it like this:
data=Import["/Users/iMacName/Desktop/sampledata.xlsx"]

File path under OSX is available with short-key “cmd+i". In the same pop up window you can also copy the file name.

Regards, Markus
POSTED BY: Markus Linder
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract