Import - Maple Programming 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 embed, format, or output options as described below

Options

 • format : string corresponding to one of the supported import formats; if unspecified and source=file, the format is inferred from the file extension of origin.
 • output : specifies the desired method for representing the imported data.
 • source : one of file or direct; specifies whether data is read from a file/URL or from memory.

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{csvFile}≔\mathrm{FileTools}:-\mathrm{JoinPath}\left(\left["example/timedata.csv"\right],\mathrm{base}=\mathrm{datadir}\right)$
 ${"C:\Program Files\Maple 2016\data\example\timedata.csv"}$ (1)
 > $\mathrm{Import}\left(\mathrm{csvFile}\right)$
 $\left[\begin{array}{ccccccc}{}& {1}& {2}& {3}& {4}& {5}& {6}\\ {1}& {"Mar 06 01:16"}& {"3/7/2005"}& {26.86091241}& {1.414301472}{}{{10}}^{{7}}& {1.505894402}{}{{10}}^{{7}}& {0.0648}\\ {2}& {"Mar 06 20:12"}& {"3/7/2005"}& {25.75624181}& {2.358229695}{}{{10}}^{{7}}& {2.497614407}{}{{10}}^{{7}}& {0.0591}\\ {3}& {"Mar 06 20:43"}& {"3/7/2005"}& {25.12706428}& {3.029212316}{}{{10}}^{{7}}& {3.314477184}{}{{10}}^{{7}}& {0.0942}\\ {4}& {"Mar 07 00:25"}& {"3/7/2005"}& {25.12249095}& {2.496855419}{}{{10}}^{{7}}& {2.656019993}{}{{10}}^{{7}}& {0.0637}\\ {5}& {"Mar 07 00:44"}& {"3/7/2005"}& {22.75919276}& {2.722498752}{}{{10}}^{{7}}& {2.818590004}{}{{10}}^{{7}}& {0.0353}\\ {6}& {"Mar 07 00:59"}& {"3/7/2005"}& {22.20631112}& {9.859010832}{}{{10}}^{{7}}& {1.029975998}{}{{10}}^{{7}}& {0.0447}\\ {7}& {"Mar 08 00:15"}& {"3/8/2005"}& {22.11477298}& {8.333640321}{}{{10}}^{{7}}& {8.579230226}{}{{10}}^{{7}}& {0.0295}\\ {8}& {"Mar 08 00:16"}& {"3/8/2005"}& {21.41227113}& {1.174272859}{}{{10}}^{{7}}& {1.217998806}{}{{10}}^{{7}}& {0.0372}\\ {\mathrm{...}}& {\mathrm{...}}& {\mathrm{...}}& {\mathrm{...}}& {\mathrm{...}}& {\mathrm{...}}& {\mathrm{...}}\end{array}\right]$ (2)

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"}$ (3)
 > $\mathrm{Import}\left(\mathrm{url}\right)$
 $\left[\begin{array}{c}{\mathrm{1..240 x 1..256}}{\mathrm{Array}}\\ {\mathrm{Data Type:}}{\mathrm{float}}{[}{8}{]}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{C_order}}\end{array}\right]$ (4)

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

 > $\mathrm{gear}≔\mathrm{FileTools}:-\mathrm{JoinPath}\left(\left["example/gear.ply"\right],\mathrm{base}=\mathrm{datadir}\right)$
 ${"C:\Program Files\Maple 2016\data\example\gear.ply"}$ (5)
 > $\mathrm{Import}\left(\mathrm{gear}\right)$

Import structured data encoded in the JSON format.

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

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

 > $\mathrm{NorthwestEurope}≔\mathrm{FileTools}:-\mathrm{JoinPath}\left(\left["example/EuropeMap.kmz"\right],\mathrm{base}=\mathrm{datadir}\right)$
 ${"C:\Program Files\Maple 2016\data\example\EuropeMap.kmz"}$ (8)
 > $\mathrm{Import}\left(\mathrm{NorthwestEurope},\mathrm{view}=\left[-13..12,46..64\right],\mathrm{title}="Northwest Europe",\mathrm{titlefont}=\left[\mathrm{Times},\mathrm{Bold},20\right]\right)$

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

 > $\mathrm{CityData}≔"City,Population Beijing,21500000 Mumbai,12478447 New York,8405837":$
 > $\mathrm{Import}\left(\mathrm{CityData},\mathrm{source}=\mathrm{direct},\mathrm{format}="CSV"\right)$
 $\left[\begin{array}{cc}{}& {\mathrm{Population}}\\ {\mathrm{Beijing}}& {21500000}\\ {\mathrm{Mumbai}}& {12478447}\\ {\mathrm{New York}}& {8405837}\end{array}\right]$ (9)

Compatibility

 • The Import command was updated in Maple 2016. By default, Import returns a DataFrame object when importing from the following rectangular formats: Excel, CSV, DIF, TSV. 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.