Import - Maple Help

Import

import external data into Maple

 Calling Sequence Import(origin, opts)

Parameters

 origin - string or ByteArray; file path or URL to a data file or the data itself opts - (optional) the format, output, source, or base options as described below

Options

 • base : one of bindir, currentdir, datadir, homedir, mapledir, tempdir, toolboxdir, or worksheetdir.
 The base option specifies a base directory. Any local file specified with parameter origin will be interpreted as a relative path under this directory.
 For the meaning of each of these values, see kernelopts or interface.
 • format : string
 The format option specifies the import format to use. This must correspond to one of the supported import formats. If omitted, the import format is inferred from the file extension and/or MIME type of origin.
 • output : symbol
 This option specifies the desired method for representing the imported data in Maple. Supported values are summarized in the following table.

Supported Output Values

 Array Audio auto boolean boolean_function ByteArray DataFrame DataSeries function Graph Image list Matrix plot string table Vector Vector[column] Vector[row]

 The default is auto, which specifies that a suitable format should be automatically inferred from the format. To determine the default behavior and supported values of output for a particular format, consult the documentation for that format.
 • source : one of file or direct
 This specifies whether the parameter origin refers to a file or URL (value file) or from a string or ByteArray in memory (value direct). The default is file.

Description

 • The Import command provides a generic mechanism for importing data in various file formats. The source data can be an external file or URL or a string or ByteArray in the current session.
 • The form which the imported data takes in Maple is determined by the format (either inferred or specified by the format option) and the output option.
 • The source option may be set to file or direct. The default, source=file, specifies that the data should be read from the file referenced by origin. In contrast source=direct means that origin is a string or ByteArray which directly contains the data. Note that source=direct requires format to be provided explicitly.
 • For details on controlling the form of imported data for a particular format, consult the documentation for that format.

Supported Formats

Examples

Import comma-separated tabular data as a DataFrame.

 > $\mathrm{Import}\left("example/timedata.csv",\mathrm{base}=\mathrm{datadir}\right)$
 ${\mathrm{DataFrame}}{}\left({{\mathrm{_rtable}}}_{{36893628856756910308}}{,}{\mathrm{rows}}{=}\left[{1}{,}{2}{,}{3}{,}{4}{,}{5}{,}{6}{,}{7}{,}{8}{,}{9}{,}{10}{,}{11}{,}{12}{,}{13}{,}{14}{,}{15}{,}{16}{,}{17}{,}{18}{,}{19}{,}{20}{,}{21}{,}{22}{,}{23}{,}{24}{,}{25}{,}{26}{,}{27}{,}{28}\right]{,}{\mathrm{columns}}{=}\left[{1}{,}{2}{,}{3}{,}{4}{,}{5}{,}{6}\right]\right)$ (7.1)

Import an image in JPEG format from a remote URL.

 > $\mathrm{url}≔"http://www.maplesoft.com/data/examples/jpg/fingerprint.jpg"$
 ${\mathrm{url}}{≔}{"http://www.maplesoft.com/data/examples/jpg/fingerprint.jpg"}$ (7.2)
 > $\mathrm{image}≔\mathrm{Import}\left(\mathrm{url}\right)$
 ${{\mathrm{_rtable}}}_{{36893628856756911868}}$ (7.3)
 > $\mathrm{ImageTools}:-\mathrm{Embed}\left(\mathrm{image}\right)$

Import a cogged gear encoded in Stanford Polygon (PLY) format.

 > $\mathrm{Import}\left("example/gear.ply",\mathrm{base}=\mathrm{datadir}\right)$

Import structured data encoded in the JSON format.

 > $\mathrm{Import}\left("example/address.json",\mathrm{base}=\mathrm{datadir}\right)$
 ${table}{}\left(\left[{"phoneNumbers"}{=}\left[{table}{}\left(\left[{"type"}{=}{"local"}{,}{"number"}{=}{"+1 \left(519\right) 747-2373"}\right]\right){,}{table}{}\left(\left[{"type"}{=}{"tollfree"}{,}{"number"}{=}{"+1 \left(800\right) 267-6583"}\right]\right){,}{table}{}\left(\left[{"type"}{=}{"fax"}{,}{"number"}{=}{"+1 \left(519\right) 747-5284"}\right]\right)\right]{,}{"address"}{=}{table}{}\left(\left[{"province"}{=}{"ON"}{,}{"postalCode"}{=}{"N2V 1K8"}{,}{"city"}{=}{"Waterloo"}{,}{"streetAddress"}{=}{"615 Kumpf Drive"}{,}{"country"}{=}{"Canada"}\right]\right){,}{"companyName"}{=}{"Maplesoft"}{,}{"founded"}{=}{1988}\right]\right)$ (7.4)

Import map data from a KMZ file and present it as a 2-D plot.

 > $\mathrm{Import}\left("example/EuropeMap.kmz",\mathrm{view}=\left[-13..12,46..64\right],\mathrm{title}="Northwest Europe",\mathrm{titlefont}=\left[\mathrm{Times},\mathrm{Bold},20\right],\mathrm{base}=\mathrm{datadir}\right)$

Import data directly from an input string while specifying the CSV format.

 > $\mathrm{CityData}≔"City,Population\nBeijing,21500000\nMumbai,12478447\nNew York,8405837\n":$
 > $\mathrm{Import}\left(\mathrm{CityData},\mathrm{source}=\mathrm{direct},\mathrm{format}="CSV"\right)$
 ${\mathrm{DataFrame}}{}\left(\left[\begin{array}{r}21500000\\ 12478447\\ 8405837\end{array}\right]{,}{\mathrm{rows}}{=}\left[{\mathrm{Beijing}}{,}{\mathrm{Mumbai}}{,}{\mathrm{New York}}\right]{,}{\mathrm{columns}}{=}\left[{\mathrm{Population}}\right]\right)$ (7.5)
 > 

Compatibility

 • The Import command was updated in Maple 2016. By default, Import returns a DataFrame object when importing from the following rectangular formats: CSV, DIF, TSV, XLS, and XLSX. Additionally Import returns a DataSeries object by default when importing from the ODS or SXC formats. Import also supports two new file formats: CNF and GEXF.
 • The Import command was introduced in Maple 2015.