Import
Usage
• Import["file.ext"] imports data from a file, assuming that it is in the format indicated by the file extension ext, and converts it to a Mathematica expression. • Import["file", "format"] imports data in the specified format from a file.
Notes
• Import attempts to give a Mathematica expression whose meaning is as close as possible to the data in the external file. • Import can handle numerical and textual data, graphics, sounds, material from notebooks, and general expressions in various formats. • The following basic formats are supported for textual and tabular data:
| "CSV" | comma-separated value tabular data (.csv) | | "Lines" | lines of text | | "List" | lines consisting of numbers or strings | | "Table" | two-dimensional array of numbers or strings | | "Text" | string of ordinary characters | | "TSV" | tab-separated value tabular data (.tsv) | | "UnicodeText" | string of 16-bit Unicode characters | | "Words" | words separated by spaces or newlines |
• "Text" and "UnicodeText" return single Mathematica strings. • "Lines" and "Words" return lists of Mathematica strings. • "List" returns a list of Mathematica numbers or strings. • "Table", "CSV" and "TSV" return a list of lists of Mathematica numbers or strings. • In "List", "Table", "CSV" and "TSV" formats, numbers can be read in C or Fortran-like "E" notation. • Numbers without explicit decimal points are returned as exact integers. • In "Table" format, columns can be separated by spaces or tabs. • In "Words" format, words can be separated by any form of white space. • In "CSV" format, columns are taken to be separated by commas, unless other settings are specified using ConversionOptions. • Import["file.txt"] uses "Text" format. • Import["file.dat"] uses "Table" format. • Import["file.csv"] uses "CSV" format. • The following additional formats are also supported for numerical data:
| "DIF" | Lotus Data Interchange Format (.dif) | | "FITS" | FITS astronomical data format (.fit, .fits) | | "HarwellBoeing" | Harwell-Boeing matrix format | | "HDF" | Hierarchical Data Format (.hdf) | | "HDF5" | HDF5 format (.h5) | | "MAT" | MAT matrix format (.mat) | | "MTX" | Matrix Market format (.mtx) | | "SDTS" | SDTS spatial GIS data format (.ddf) | | "XLS" | Excel spreadsheet format (.xls) |
• When appropriate, numerical data is imported as SparseArray objects. • The following format yields a list of expressions suitable for input to NMinimize:
| "MPS" | MPS Mathematical Programming System format (.mps) |
• Two-dimensional graphics formats are imported as Graphics objects; sound formats are imported as Sound objects. • Animated graphics are imported as lists of Graphics objects. • The following formats yield expressions of the form Graphics[data, opts]:
| "APS" | Mathematica abbreviated PostScript (.aps) | | "EPS" | Encapsulated PostScript (.eps) | | "EPSI" | Encapsulated PostScript with image preview (.epsi) | | "EPSTIFF" | Encapsulated PostScript with TIFF preview |
• The following formats yield expressions of the form Graphics[Raster[data], opts]:
| "BMP" | Microsoft bitmap format (.bmp) | | "DICOM" | DICOM medical imaging format (.dcm, .dic) | | "GIF" | GIF and animated GIF (.gif) | | "JPEG" | JPEG (.jpg, .jpeg) | | "MGF" | Mathematica system-independent raster graphics format (.mgf) | | "PBM" | portable bitmap format (.pbm) | | "PCX" | PCX format (.pcx) | | "PGM" | portable graymap format (.pgm) | | "PNG" | PNG format (.png) | | "PNM" | portable anymap format (.pnm) | | "PPM" | portable pixmap format (.ppm) | | "TIFF" | TIFF (.tif, .tiff) | | "XBitmap" | X window system bitmap (.xbm) |
• For indexed raster formats such as "GIF", the data in Raster consists of integers, and a ColorFunction is used to specify a color map. • For true color formats such as "JPEG", the data in Raster consists for example of explicit RGB triples. • The following formats return objects of the form Graphics3D[data, opts]:
| "DXF" | AutoCAD drawing interchange format (.dxf) | | "STL" | STL stereolithography format (.stl) |
• The following formats yield expressions of the form Sound[SampledSoundList[data, r]]:
| "AIFF" | AIFF format (.aif, .aiff) | | "AU" | law encoding (.au) | | "SND" | sound file format (.snd) | | "WAV" | Microsoft wave format (.wav) |
• The following gives a notebook expression Notebook[ ... ] from a Mathematica notebook file:
| "NB" | Mathematica notebook format (.nb) |
• The following XML formats give various types of expressions:
| "ExpressionML" | arbitrary expression | | "MathML" | mathematical expression or boxes (.mml) | | "NotebookML" | notebook expression (.nbml) | | "SymbolicXML" | SymbolicXML expression | | "XML" | determined by content (.xml) |
• With format "MathML", MathML presentation elements are if possible imported as mathematical expressions using TraditionalForm interpretation rules. Otherwise, they are imported as box expressions. • With format "SymbolicXML", XML data of any document type is imported as a SymbolicXML expression. • With format "XML", Import will recognize MathML, NotebookML, and ExpressionML and interpret them accordingly. Other XML will be imported as SymbolicXML. • The following formats can be used for general expressions:
| "Dump" | internal binary format (.mx) | | "Expression" | InputForm textual format (.m) | | "ExpressionML" | XML-based ExpressionML format |
• The following formats can be used for raw binary data:
| "Bit" | single bits (0 or 1) | | "Byte" | 8-bit unsigned integers | | "Character8" | 8-bit characters | | "Character16" | 16-bit characters | | "Complex64" | IEEE single-precision complex numbers | | "Complex128" | IEEE double-precision complex numbers | | "Complex256" | IEEE quad-precision complex numbers | | "Integer8" | 8-bit signed integers | | "Integer16" | 16-bit signed integers | | "Integer32" | 32-bit signed integers | | "Integer64" | 64-bit signed integers | | "Integer128" | 128-bit signed integers | | "Real32" | IEEE single-precision real numbers | | "Real64" | IEEE double-precision real numbers | | "Real128" | IEEE quad-precision real numbers | | "TerminatedString" | null-terminated strings of 8-bit characters | | "UnsignedInteger8" | 8-bit unsigned integers | | "UnsignedInteger16" | 16-bit unsigned integers | | "UnsignedInteger32" | 32-bit unsigned integers | | "UnsignedInteger64" | 64-bit unsigned integers | | "UnsignedInteger128" | 128-bit unsigned integers |
• In each case, a list of individual data elements is returned. • Byte ordering is specified by the ByteOrdering option. • The following general options for all formats can be given: • Many details can be specified in the setting for ConversionOptions. • Possible formats accepted by Import are given in the list $ImportFormats. • Import["!prog", "format"] imports data from a pipe. • New in Version 4; modified in 5.1.
|