Import Tabular Data - Maple Help

Home : Support : Online Help : Getting Started : How Do I... : Import Tabular Data

How Do I

 Import Tabular Data?

 Supported Formats Maple supports many different import and export file formats including csv, tsv, Excel, ods, and more. To see a full list of supported formats, see the Formats help page.

Using Commands

Many commands support importing data files directly from files stored on disk or online. Maple stores many sample data files in the Maple data directory. This directory can be found under "data" in the Maple installation folder.

 > $\mathrm{kernelopts}\left(\mathrm{datadir}\right);$

Import

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. 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 SXC or TSV formats.

Import comma-separated tabular data as a DataFrame.

 > $\mathrm{csvFile}â‰”\mathrm{FileTools}:-\mathrm{JoinPath}\left(\left["datasets","iris.csv"\right],\mathrm{base}=\mathrm{datadir}\right):$

 > $\mathrm{Import}\left(\mathrm{csvFile}\right);$

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

 ${\mathrm{DataFrame}}{}\left({{\mathrm{_rtable}}}_{{18446746122870092494}}{,}{\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}{,}{29}{,}{30}{,}{31}{,}{32}{,}{33}{,}{34}{,}{35}{,}{36}{,}{37}{,}{38}{,}{39}{,}{40}{,}{41}{,}{42}{,}{43}{,}{44}{,}{45}{,}{46}{,}{47}{,}{48}{,}{49}{,}{50}{,}{51}{,}{52}{,}{53}{,}{54}{,}{55}{,}{56}{,}{57}{,}{58}{,}{59}{,}{60}{,}{61}{,}{62}{,}{63}{,}{64}{,}{65}{,}{66}{,}{67}{,}{68}{,}{69}{,}{70}{,}{71}{,}{72}{,}{73}{,}{74}{,}{75}{,}{76}{,}{77}{,}{78}{,}{79}{,}{80}{,}{81}{,}{82}{,}{83}{,}{84}{,}{85}{,}{86}{,}{87}{,}{88}{,}{89}{,}{90}{,}{91}{,}{92}{,}{93}{,}{94}{,}{95}{,}{96}{,}{97}{,}{98}{,}{99}{,}{100}{,}{101}{,}{102}{,}{103}{,}{104}{,}{105}{,}{106}{,}{107}{,}{108}{,}{109}{,}{110}{,}{111}{,}{112}{,}{113}{,}{114}{,}{115}{,}{116}{,}{117}{,}{118}{,}{119}{,}{120}{,}{121}{,}{122}{,}{123}{,}{124}{,}{125}{,}{126}{,}{127}{,}{128}{,}{129}{,}{130}{,}{131}{,}{132}{,}{133}{,}{134}{,}{135}{,}{136}{,}{137}{,}{138}{,}{139}{,}{140}{,}{141}{,}{142}{,}{143}{,}{144}{,}{145}{,}{146}{,}{147}{,}{148}{,}{149}{,}{150}\right]{,}{\mathrm{columns}}{=}\left[{\mathrm{Sepal Length}}{,}{\mathrm{Sepal Width}}{,}{\mathrm{Petal Length}}{,}{\mathrm{Petal Width}}{,}{\mathrm{Species}}\right]\right)$ (2.1.1)
 > $\mathrm{CityData}â‰”"City,Population Beijing,21500000 Mumbai,12478447 New York,8405837":$
 > $\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)$ (2.1.2)

ImportMatrix

The ImportMatrix command can also be used to import tabular data and store the data as a Vector or Matrix. In contrast to the Import command, the ImportMatrix command assumes that the incoming data is tabularly structured information, and cannot be used to import images, or other file types.

Import a MATLAB® ASCII data file with entries format.

 > $\mathrm{matlabFile}â‰”\mathrm{FileTools}:-\mathrm{JoinPath}\left(\left["example","MatlabData.txt"\right],\mathrm{base}=\mathrm{datadir}\right):$
 > $Aâ‰”\mathrm{ImportMatrix}\left(\mathrm{matlabFile},\mathrm{source}=\mathrm{MATLAB},\mathrm{format}=\mathrm{entries},\mathrm{transpose}=\mathrm{true}\right)$
 ${{\mathrm{_rtable}}}_{{18446746122870327422}}$ (2.2.1)

ExcelTools Import

The Import command in the ExcelTools package is designed for working with Excel spreadsheet files providing a mechanism to import full spreadsheets or specific ranges of cells stored in Excel spreadsheets.

 > $\mathrm{ExcelFile}≔\mathrm{FileTools}:-\mathrm{JoinPath}\left(\left["Excel","ExperimentalData.xls"\right],\mathrm{base}=\mathrm{datadir}\right):$
 > $\mathrm{ExcelTools}:-\mathrm{Import}\left(\mathrm{ExcelFile}\right);$
 ${{\mathrm{_rtable}}}_{{18446746122865206918}}$ (2.3.1)

It is also possible to import information in other spreadsheets in the file as well as specify cell ranges:

 > $\mathrm{ExcelTools}:-\mathrm{Import}\left(\mathrm{ExcelFile},"Sheet2","A2:B12"\right)$
 ${{\mathrm{_rtable}}}_{{18446746122865207374}}$ (2.3.2)

 readdata The readdata command reads numeric data from a text file into Maple. The data in the file must consist of integers or floating-point values arranged in columns, separated by white space, and it is returned in a list or list of lists.

scanf

The scanf command allows you to read from the terminal using a specified format. The formatting information is provided by a format string.

The sscanf command below reads an integer, a space, a character, and a floating-point value from the string given as the first argument.

 > sscanf("892 123.456E7","%d %c%f");
 $\left[{892}{,}{"1"}{,}{2.3456}{}{{10}}^{{8}}\right]$ (2.4.2.1)

Several format codes are available for use with scanf. A few of the more commonly used ones are mentioned here.

"d" -- integer

"f" -- floating-point number

"c" -- character

"s" -- string

"a" -- Maple expression

 Data Import Assistant The Import Data Assistant is an interactive interface to import external data into Maple. You can also launch the dialog from the menu bar. From the Tools menu, select Assistants and then Import Data.
 DataSet Search The Data Set Search assistant is an interactive graphical interface for searching built-in and online data sources.   It is possible to search for available data sources from Maple's help search box:
 Related Topics The How Do I... topics cover the essentials for doing mathematics in Maple. Learn more about available tools and features, such as palettes and the context panel. Refer to Help>Quick Reference for basic Getting Started tips.