此为 Mathematica 7 文档,内容基于更早版本的 Wolfram 语言
查看最新文档(版本11.1)
Import/Export 导入/导出 格式

Table (.dat)

Generic tabular data.
Stores numerical and textual information, formatted as a table.
Supports user-defined field and record separators, field delimiters, currency tokens, and number formats.
Plain text format.
  • Import and Export fully support the Table format and provide various data conversion and formatting options.
  • Import automatically recognizes common number formats, including C and Fortran notations.
  • Numbers without decimal points are imported as integers.
  • Import["file.dat"] imports a Table file, returning a list of lists.
  • Export["file.dat", expr] exports a two-dimensional array or a Grid to a Table file.
  • Import["file.dat"] returns a two-dimensional array of strings and numbers, representing the rows and columns stored in the file.
  • Export["file.dat", array] formats array as rows and columns using the CForm of each element.
  • Mathematica automatically transforms arbitrary expressions to a list of lists when exporting to the Table format.
  • Import["file.dat", elem] imports the specified element from a Table file.
  • Import["file.dat", {elem, suba, subb, ...}] imports a subelement.
  • Import["file.dat", {{elem1, elem2, ...}}] imports multiple elements.
  • The import format can be specified with Import["file", "Table"] or Import["file", {"Table", elem, ...}].
  • Export["file.dat", expr, elem] creates a Table file by treating expr as specifying element elem.
  • Export["file.dat", {expr1, expr2, ...}, {{elem1, elem2, ...}}] treats each expri as specifying the corresponding elemi.
  • Export["file.dat", expr, opt1->val1, ...] exports expr with the specified option elements taken to have the specified values.
  • Export["file.dat", {elem1->expr1, elem2->expr2, ...}, "Rules"] uses rules to specify the elements to be exported.
  • See the reference pages for full general information on Import and Export.
  • Save Selection As exports the selected part of a notebook as a Table file.
"Elements"list of elements and options available in this file
"Rules"full list of rules for each element and option
"Options"list of rules for options, properties and settings
  • Data representation elements:
"Data"two-dimensional array, representing the rows and columns
"Grid"table data as a Grid object
AlignmentNonehow data is aligned within table columns
CharacterEncoding"UTF8"raw character encoding used in the file
CharacterEncoding"ASCII"raw character encoding used in the file
"TextDelimiters"Automaticstring or list of strings used to delimit non-numeric fields
  • By default, Export delimits text fields containing the field separator with double-quote characters.
  • With an explicit setting of "TextDelimiters", Export always uses the specified string tokens to delimit text fields, effectively cycling through the list of delimiters.
  • With "TextDelimiters" -> {"<", ">"} , Export wraps text fields in angular brackets.
  • Double-quote characters delimiting text fields are not imported by default.
"CurrencyTokens"{{"$", "£", "¥", "€"}, {"c", "¢", "p", "F"}}currency units to be skipped when importing numerical values
"DateStringFormat"Nonedate format, given as a DateString specification
"FieldSeparators"{" ","\t"}string tokens taken to separate columns
"IgnoreEmptyLines"Falsewhether to ignore empty lines
"LineSeparators"{"\r\n","\n","\r"}string tokens taken to separate rows
"Numeric"Truewhether to import data fields as numbers if possible
"NumberPoint""."decimal point string
"NumberSigns"{"-","+"}strings to use for signs of negative and positive numbers
"RepeatedSeparators"Truewhether to parse a sequence of field separators as a single separator
"HeaderLines"0number of lines to skip at the beginning of the file
  • Import converts table entries formatted as specified by the "DateStringFormat" option to a DateList representation of the form {y, m, d, h, m, s}.
  • Empty lines and lines containing only whitespace characters are converted to an empty list by default. With "IgnoreEmptyLines" set to True, Import will skip empty lines.
  • With "Numeric" -> False, numbers will be imported as strings in the form they appear in the file.
  • With the default setting for "LineSeparators", Import automatically recognizes all common conventions for the encoding of line-separator characters.
"FieldSeparators""\t"string token used to separate columns
"TableHeadings"Noneheadings for table columns and rows
  • "TableHeadings" can be set to the following values:
Noneno labels
Automaticgives successive integer labels for columns and rows
{"col1","col2",...}list of column labels
{rhead,chead}specifies separate labels for the rows and columns
  • Export encodes line separator characters using the convention of the computer system on which Mathematica is being run.
Export an array of random numbers as a table:
In[1]:=
Click for copyable input
Out[1]=
Export a table formatted as a grid:
In[2]:=
Click for copyable input
Out[2]=
Import the generated file:
In[3]:=
Click for copyable input
Out[3]=
Use ExportString to create a formatted version of an array:
In[4]:=
Click for copyable input
Out[4]=
 
Import a tabular data file that uses vertical bars as field separators:
In[1]:=
Click for copyable input
Out[1]=
 
Import converts dates to a Mathematica DateList specification if the date format is specified:
In[1]:=
Click for copyable input
Out[1]=
 
Create a UTF-8 encoded text file that contains currency tokens:
In[1]:=
Click for copyable input
Out[1]=
When importing this file, currency tokens are automatically skipped:
In[2]:=
Click for copyable input
Out[2]=
 
Mathematica automatically converts expressions to a list of lists when exporting to the Table format:
In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=