文本文件
- 版本 :2022.1 及更高版本
本文介绍如何将 Tableau 连接到文本文件数据并设置数据源。Tableau 连接到带分隔符的文本文件(*.txt、*.csv、*.tab、*.tsv)。
建立连接并设置数据源
打开 Tableau 后,在“连接”下,单击“文本文件”。
选择要连接到的文件,然后单击“打开”。
注意:从 Tableau 2020.2 开始,不再支持旧版 Excel 和文本连接。请参阅 Tableau 社区中的旧版连接备选方案文档,了解使用旧版连接的替代方法。
在数据源页面上,执行以下操作:
(可选)选择页面顶部的默认数据源名称,然后输入要在 Tableau 中使用的唯一数据源名称。例如,使用数据源命名约定,帮助数据源的其他用户确定要连接到哪个数据源。默认名称是根据文件名自动生成的。
单击工作表选项卡以开始分析。
使用自定义 SQL 连接到特定查询,而不是整个数据源。有关详细信息,请参阅连接到自定义 SQL 查询。
注意:对于文本文件,自定义 SQL 仅在使用旧连接或在 Tableau Desktop 8.2 之前创建的工作簿中可用。
文本文件数据源示例
下面是文本文件数据源的示例:
可选设置
您可以在构建视图之前设置以下选项。
获取更多数据
通过添加更多表或连接到其他数据库中的数据,将更多数据放入数据源。
从当前文件添加更多数据:从左窗格中,将其他表拖到画布上,以使用联接或并集合并数据。有关详细信息,请参阅联接数据或合并数据。
从不同的数据库添加更多数据:在左窗格中,单击“连接”旁边的“添加”。有关详细信息,请参阅联接数据。
If a connector you want is not listed in the left pane, select Data > New Data Source to add a new data source. For more information, see Blend Your Data.
Clean your data with Data Interpreter
If Tableau detects that it can help optimize your data source for analysis, it prompts you to use Data Interpreter. Data Interpreter can detect sub-tables that you can use and remove unique formatting that might cause problems later on in your analysis. For more information, see Clean Data from Excel, CSV, PDF, and Google Sheets with Data Interpreter.
Set text file options
On the canvas, click the table drop-down arrow and then select whether the first row contains column names. This option is selected by default. Alternatively, you can have Tableau generate names when you connect. These names can be changed later. You can also select Text file properties to specify the following:
Select the character that is used to separate the columns. Select from the list of characters or select Other to type in a custom character.
Select the text qualifier that encloses values in the text file.
Select a character set that describes the text file encoding. The available encodings are based on the operating system you are using. For example, on Windows, ANSI is listed as windows-1252 and OEM is listed as 437.
Note: In workbooks created prior to Tableau Desktop 8.2 or that use the legacy connection, you can select ANSI, OEM, UTF-8, UTF-16, or Other. When you select Other, you must specify the character set in the provided text field. This value is verified when the connection is attempted.
Select the locale by which the file should be parsed. This option tells Tableau which decimal and thousands separator to use.
Review the data, pivot, split, and create calculations
The first 1,000 rows of the data in the data source are automatically displayed below the canvas in the data grid. If you add tables, remove tables, or make changes to the join conditions, the data grid updates with your changes. You can also do the following in the data grid:
Change the data type or geographical role of a column by clicking the data type icon.
Hide a field by clicking the column drop-down arrow and selecting Hide.
Rename a field by double-clicking the field name.
Reset a field name by clicking the column drop-down arrow and selecting Reset Name.
Sort fields in both the data grid and metadata grid by selecting a sort option from the Sort fields drop-down list.
Sort rows in the data grid by clicking the sort button next to the column name.
Pivot fields to transform data in a crosstab format into a columnar format. This is only available for non-legacy connection types. For more information, see Pivot Data from Columns to Rows.
Split a string field into multiple fields. This is only available for non-legacy connection types. For more information, see Split a Field into Multiple Fields.
Create new calculations based on existing field in the Tableau data source. Click the column drop-down arrow and select Create Calculated Field.
Copy values in the grid by selecting the values and then pressing Ctrl+C (Command-C on a Mac). Alternatively, to copy values in the metadata grid, select the values, right-click (Control-click on a Mac), and then select Copy.
Examine the data source structure and perform management tasks
Use the metadata area to quickly examine the general structure of the Tableau data source and its fields. If you are working with a particularly large data source, use the metadata area to perform routine data management tasks such as hide multiple fields at once or quickly rename or reset fields.
Connect live or use an extract
At the top of the Data Source page, select Live or Extract mode. If you choose to create an extract, the Edit link displays. Click Edit to set up filters that define a subset of the data that you want to include in the extract. For more information, see Extract Your Data.
Add data source filters
At the top of the data source page, click Add to add data source filters to control what data is used in included in the data source and therefore restrict the visibility and use of the fields in the data source.
Best practices
Collect files in a single directory
Collect all relevant text files for a multi-table connection in a single directory, with nothing else in that directory, so that users cannot inadvertently select a file that is not appropriate for the connection.
Text file column width and size considerations
If the text file contains columns that are more than 254 characters wide, Tableau cannot use these fields for workbooks that were created before Tableau Desktop 8.2 or that use the legacy connection. Either remove the columns, modify them to fit within 254 characters prior to connecting in Tableau, or upgrade the text file data source.
Large text files often perform poorly as a data source, because the queries can take a long time.
关于 .ttde 和 .hhyper 文件
在浏览计算机目录时,您可能会注意到 .ttde 或 .hhyper 文件。创建连接到数据的 Tableau 数据源时,Tableau 会创建一个 .ttde 或 .hhyper 文件。此文件也称为卷影数据提取,用于帮助提高数据源在 Tableau Desktop 中的加载速度。尽管影子数据提取包含与标准 Tableau 数据提取类似的基础数据和其他信息,但影子数据提取以不同的格式保存,不能用于恢复数据。
在某些情况下,您可能需要从计算机中删除影子数据提取。有关详细信息,请参阅 Tableau 知识库中的由于影子提取而导致的磁盘空间不足。