Table (.dat)

背景

    • 通用的表格数据.
    • 存储数值和文本信息,格式化为一个表格.
    • 支持用户定义的字段和记录分隔符、字段分隔符、货币令牌以及数字格式.
    • 纯文本格式.

Import 与 Export

  • Import["file.dat"] returns a list of lists containing strings and numbers representing the rows and columns stored in the file.
  • Import["file.dat",elem] 从 Table 文件中导入指定的参数.
  • Import["file.dat",{elem,subelem1,}] imports subelements subelemi, useful for partial data import.
  • Import["file.dat",{{elem1,elem2,}}] 导入多个参数.
  • 导入格式可以由 Import["file","Table"]Import["file",{"Table",elem,}] 指定.
  • Export["file.dat",expr] creates a Table file from expr.
  • Supported expressions expr include:
  • {v1,v2,}a single column of data
    {{v11,v12,},{v21,v22,},}lists of rows of data
    arrayan array such as SparseArray, QuantityArray, etc.
    tseriesa TimeSeries, EventSeries or a TemporalData object
    Dataset[]a dataset
    Tabular[]a tabular object
  • 请到以下参考页面了解完整的基本信息:
  • Import, Export从文件导入或导出到文件
    CloudImport, CloudExport从云对象导入或导出到云对象
    ImportString, ExportString从字符串导入或导出到字符串
    ImportByteArray, ExportByteArray从字节数组导入或导出到字节数组

笔记本界面

  • 选择另存为 把笔记本的选择部分导出为一个 Table 文件.

Import 参数

  • Import 的通用参数:
  • "Elements" 该文件可用的参数和选项列表
    "Summary"文件摘要
    "Rules"所有可用参数的规则列表
  • 表示数据的参数:
  • "Data"二维数组,表示行和列
    "Grid"作为一个 Grid 对象的表格数据
    "Tabular"table data as a Tabular object
  • 默认情况下,ImportExport 使用"Data"参数.

选项

  • ImportExport 选项:
  • "TextDelimiters"Automatic用于分隔非数字字段的字符串或字符串列表
  • 默认情况下,Export 划分包含具有双引号字符的字段分隔符.
  • 当具有显式设置 "TextDelimiters"Export 总是使用指定的字符串令牌分隔文本字段,有效地循环于分隔符列表.
  • "TextDelimiters"->{"<",">"}Export 封装文本字段于尖括号内.
  • 默认情况下,不导入双引号字符分隔的文本字段.
  • Import 选项:
  • CharacterEncoding"ISOLatin1"文件中行字符串使用的编码
    "CurrencyTokens"{{"$", "£", "¥", "€"}, {"c", "¢", "p", "F"}}当导入数值值时,跳过的货币单位
    "DateStringFormat"NoneDateString 规范给出的日期格式
    "FieldSeparators"{" ","t"}分隔列的字符串令牌
    "HeaderLines"0文件开头处跳过的行数
    "IgnoreEmptyLines"False是否忽略空行
    "LineSeparators"{"r\n","n","\r"}分隔行的字符串令牌
    "NumberPoint""."用于小数点的字符串
    "NumberSigns"{"-","+"}负数和正数的符号字符串
    "Numeric"True如果可能的话是否按数字导入数据字段
    "RepeatedSeparators"True是否解析字段分隔符序列为一单个分隔符
  • CharacterEncoding -> AutomaticImport 尝试推断文件的字符编码.
  • Import 把由 "DateStringFormat" 选项指定格式化的表格项转换成一个 DateObject.
  • 默认情况下,空行和仅包含空白字符的行被转换成以空白列表. 如果 "IgnoreEmptyLines" 设为 TrueImport 将跳过空行.
  • "Numeric" -> False,数字将按它们在文件中显示的字符串形式导入.
  • 当默认设置为 "LineSeparators"Import 自动识别行分隔字符编码的所有常用规范.
  • Export 选项:
  • AlignmentNone在表格列中数据是如何对齐的
    CharacterEncoding"UTF8"文件中行字符串使用的编码
    "FieldSeparators""\t"用于分隔列的字符串令牌
    "TableHeadings"None表格列与行的标头
  • Alignment 的可能设定为 NoneLeftCenterRight.
  • "TableHeadings"可被设为下列值:
  • None没有标签
    Automatic给出列与行的连续整数标签
    {"col1","col2",}列标签列表
    {rhead,chead}指定行与列的独立标签
  • Export 使用运行 Wolfram 语言的计算机系统的常用规范编码行分隔字符.

范例

打开所有单元关闭所有单元

基本范例  (4)

Import data from a Table file:

Import data as a Tabular object:

Summary of a table file:

将随机数数组导出为一个表格:

范围  (8)

Import  (3)

Show all elements available in the file:

Import a tabular data file that uses vertical bars as field separators:

Import converts dates to a Wolfram Language DateObject specification if the date format is specified:

Export  (5)

Create a UTF-8 encoded text file that contains currency tokens:

When importing this file, currency tokens are automatically skipped:

The Wolfram Language automatically converts expressions to a list of lists when exporting to the Table format:

Table export uses the CForm for Real values:

Export an array of random numbers as a table:

Export a table formatted as a grid:

Import the generated file:

Use ExportString to create a formatted version of an array:

Import Elements  (5)

Data  (2)

Import data from a table file:

This is also the default element:

Create a text grid from data:

Grid  (1)

Import data from a table file as Grid:

Summary  (1)

Get the file summary:

Tabular  (1)

Get the data from a file as a Tabular object:

Import Options  (11)

CharacterEncoding  (1)

The character encoding can be set to any value from $CharacterEncodings:

"CurrencyTokens"  (1)

Currency tokens are automatically skipped:

Use the "CurrencyTokens"->None to include all currency tokens:

"DateStringFormat"  (1)

By default, no date conversion is happening:

Convert dates to a DateObject using the date format specified:

"FieldSeparators"  (1)

By default, " " and "t" are used as a field separators:

Use " | " as a field separator:

"HeaderLines"  (1)

Table files may include comment lines:

Specify the number of comment lines to skip:

"IgnoreEmptyLines"  (1)

Use "IgnoreEmptyLines" to remove lines with no data from the imported data:

"LineSeparators"  (1)

Use "LineSeparators" to separate rows:

"NumberPoint"  (1)

By default, "." is used to specify decimal point character for floating-point data:

Use "NumberPoint" option to specify decimal point character for floating-point data:

"NumberSigns"  (1)

By default, "-" and "+" are used for signs of negative and positive numbers:

Use "NumberSigns" option to specify signs of negative and positive numbers:

"Numeric"  (1)

By default, Import interprets numbers:

Use "Numeric"->False to import everything as strings:

"RepeatedSeparators"  (1)

By default, a sequence of field separators is parsed as a single separator:

Use "RepeatedSeparators"->False to disable that behavior:

Export Options  (4)

Alignment  (1)

By default, no additional characters are added for any alignment:

Left-align column values:

Center-align column values:

CharacterEncoding  (1)

The character encoding can be set to any value from $CharacterEncodings:

"FieldSeparators"  (1)

By default, "\t" is used to separate columns:

Use "FieldSeparators" option to specify a different separator:

"TableHeadings"  (1)

Export data using custom column headers:

Export data using custom column and row headers:

Export data using successive integer labels for columns and rows: