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 array an array such as SparseArray, QuantityArray, etc. tseries a TimeSeries, EventSeries or a TemporalData object Dataset[…] a dataset Tabular[…] a tabular object - 请到以下参考页面了解完整的基本信息:
-
Import, Export 从文件导入或导出到文件 CloudImport, CloudExport 从云对象导入或导出到云对象 ImportString, ExportString 从字符串导入或导出到字符串 ImportByteArray, ExportByteArray 从字节数组导入或导出到字节数组
选项



- Import 与 Export 选项:
-
"TextDelimiters" Automatic 用于分隔非数字字段的字符串或字符串列表 - 默认情况下,Export 划分包含具有双引号字符的字段分隔符.
- 当具有显式设置 "TextDelimiters",Export 总是使用指定的字符串令牌分隔文本字段,有效地循环于分隔符列表.
- 当 "TextDelimiters"->{"<",">"},Export 封装文本字段于尖括号内.
- 默认情况下,不导入双引号字符分隔的文本字段.
- Import 选项:
-
CharacterEncoding "ISOLatin1" 文件中行字符串使用的编码 "CurrencyTokens" {{"$", " ", "
", "
"}, {"c", "
", "p", "F"}}
当导入数值值时,跳过的货币单位 "DateStringFormat" None 按 DateString 规范给出的日期格式 "FieldSeparators" {" ","∖t"} 分隔列的字符串令牌 "HeaderLines" 0 文件开头处跳过的行数 "IgnoreEmptyLines" False 是否忽略空行 "LineSeparators" {"∖r\n","∖n","\r"} 分隔行的字符串令牌 "NumberPoint" "." 用于小数点的字符串 "NumberSigns" {"-","+"} 负数和正数的符号字符串 "Numeric" True 如果可能的话是否按数字导入数据字段 "RepeatedSeparators" True 是否解析字段分隔符序列为一单个分隔符 - 用 CharacterEncoding -> Automatic,Import 尝试推断文件的字符编码.
- Import 把由 "DateStringFormat" 选项指定格式化的表格项转换成一个 DateObject.
- 默认情况下,空行和仅包含空白字符的行被转换成以空白列表. 如果 "IgnoreEmptyLines" 设为 True,Import 将跳过空行.
- 当 "Numeric" -> False,数字将按它们在文件中显示的字符串形式导入.
- 当默认设置为 "LineSeparators",Import 自动识别行分隔字符编码的所有常用规范.
- Export 选项:
-
Alignment None 在表格列中数据是如何对齐的 CharacterEncoding "UTF8" 文件中行字符串使用的编码 "FieldSeparators" "\t" 用于分隔列的字符串令牌 "TableHeadings" None 表格列与行的标头 - Alignment 的可能设定为 None、Left、Center 和 Right.
- "TableHeadings"可被设为下列值:
-
None 没有标签 Automatic 给出列与行的连续整数标签 {"col1","col2",…} 列标签列表 {rhead,chead} 指定行与列的独立标签 - Export 使用运行 Wolfram 语言的计算机系统的常用规范编码行分隔字符.
范例
打开所有单元关闭所有单元基本范例 (4)
范围 (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:
Use ExportString to create a formatted version of an array:
Import Elements (5)
Import Options (11)
CharacterEncoding (1)
The character encoding can be set to any value from $CharacterEncodings:
"CurrencyTokens" (1)
"DateStringFormat" (1)
By default, no date conversion is happening:
Convert dates to a DateObject using the date format specified:
"FieldSeparators" (1)
"HeaderLines" (1)
"NumberPoint" (1)
"NumberSigns" (1)
"Numeric" (1)
By default, Import interprets numbers:
Export Options (4)
Alignment (1)
CharacterEncoding (1)
The character encoding can be set to any value from $CharacterEncodings: