 CSV - Maple Help

Comma-Separated Values (.csv) File Format

Comma-Separated Values Description

 • CSV (Comma-Separated Values) is a simple text-based format for tabular data in which rows of data appear on subsequent lines and columns are delimited by commas.
 • The ImportMatrix command recognizes two variants of CSV files, standard CSV and Microsoft CSV. For details on the differences between these formats, see sscanf.
 • The ExportMatrix command can write tabular data to the CSV format.
 • The general-purpose commands Import and Export also support this format.
 • The default output from Import for this format is a DataFrame. To produce a Matrix, use Import(...,output=Matrix). Notes

 • Content-Type: text/csv, text/comma-separated-values Examples

Import a CSV file as a DataFrame.

 > $\mathrm{Import}\left("example/timedata.csv",\mathrm{base}=\mathrm{datadir}\right)$
 $\begin{array}{c}\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}\\ {9}& {"Mar 08 00:16"}& {"3/8/2005"}& {21.33253315}& {4.950350549}{×}{{10}}^{{6}}& {5.239008009}{×}{{10}}^{{7}}& {0.0583}\\ {10}& {"Mar 08 00:16"}& {"3/8/2005"}& {20.62752309}& {1.765508208}{×}{{10}}^{{7}}& {1.870092003}{×}{{10}}^{{7}}& {0.0592}\\ {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}\end{array}\right]\\ \hfill {\text{28 x 6 DataFrame}}\end{array}$ (1)

Import a CSV file as a Matrix.

 > $\mathrm{Import}\left("example/timedata.csv",\mathrm{base}=\mathrm{datadir},\mathrm{output}=\mathrm{Matrix}\right)$
 $\begin{array}{c}\left[\begin{array}{cccccc}{"Mar 06 01:16"}& {"3/7/2005"}& {26.86091241}& {1.414301472}{×}{{10}}^{{7}}& {1.505894402}{×}{{10}}^{{7}}& {0.0648}\\ {"Mar 06 20:12"}& {"3/7/2005"}& {25.75624181}& {2.358229695}{×}{{10}}^{{7}}& {2.497614407}{×}{{10}}^{{7}}& {0.0591}\\ {"Mar 06 20:43"}& {"3/7/2005"}& {25.12706428}& {3.029212316}{×}{{10}}^{{7}}& {3.314477184}{×}{{10}}^{{7}}& {0.0942}\\ {"Mar 07 00:25"}& {"3/7/2005"}& {25.12249095}& {2.496855419}{×}{{10}}^{{7}}& {2.656019993}{×}{{10}}^{{7}}& {0.0637}\\ {"Mar 07 00:44"}& {"3/7/2005"}& {22.75919276}& {2.722498752}{×}{{10}}^{{7}}& {2.818590004}{×}{{10}}^{{7}}& {0.0353}\\ {"Mar 07 00:59"}& {"3/7/2005"}& {22.20631112}& {9.859010832}{×}{{10}}^{{7}}& {1.029975998}{×}{{10}}^{{7}}& {0.0447}\\ {"Mar 08 00:15"}& {"3/8/2005"}& {22.11477298}& {8.333640321}{×}{{10}}^{{7}}& {8.579230226}{×}{{10}}^{{7}}& {0.0295}\\ {"Mar 08 00:16"}& {"3/8/2005"}& {21.41227113}& {1.174272859}{×}{{10}}^{{7}}& {1.217998806}{×}{{10}}^{{7}}& {0.0372}\\ {"Mar 08 00:16"}& {"3/8/2005"}& {21.33253315}& {4.950350549}{×}{{10}}^{{6}}& {5.239008009}{×}{{10}}^{{7}}& {0.0583}\\ {"Mar 08 00:16"}& {"3/8/2005"}& {20.62752309}& {1.765508208}{×}{{10}}^{{7}}& {1.870092003}{×}{{10}}^{{7}}& {0.0592}\\ {⋮}& {⋮}& {⋮}& {⋮}& {⋮}& {⋮}\end{array}\right]\\ \hfill {\text{28 × 6 Matrix}}\end{array}$ (2)

Export 100 random three-dimensional points to a CSV file in the home directory of the current user.

 > $P≔\mathrm{LinearAlgebra}:-\mathrm{RandomMatrix}\left(100,3\right)$
 ${P}{≔}\begin{array}{c}\left[\begin{array}{ccc}{-80}& {-79}& {-38}\\ {-19}& {75}& {91}\\ {-62}& {-85}& {-1}\\ {81}& {-19}& {63}\\ {22}& {57}& {-23}\\ {50}& {83}& {-63}\\ {78}& {-45}& {-26}\\ {-8}& {68}& {30}\\ {-90}& {58}& {10}\\ {-81}& {-43}& {22}\\ {⋮}& {⋮}& {⋮}\end{array}\right]\\ \hfill {\text{100 × 3 Matrix}}\end{array}$ (3)
 > $\mathrm{Export}\left("points.csv",P,\mathrm{base}=\mathrm{homedir}\right)$
 ${1025}$ (4) Compatibility

 • With Maple 2016, the Import command applied to CSV files now produces DataFrame objects by default.