- Julia Cookbook
- Jalem Raj Rohit
- 227字
- 2021-07-08 11:12:45
Handling data with TSV files
In this section, we will explain how to handle Tab Separated Values (TSV) files.
Getting ready
The DataFrames
package is needed to deal with TSV files. So, as it is already installed as instructed in the previous section, we can move ahead and make sure that all the packages are up-to-date with the following command:
Pkg.update()
How to do it...
TSV files, as the name suggests, are files whose contents are separated by commas. TSV files can be accessed and read into the REPL process by the following method:
- Assign a variable to the local source directory of the file:
s = "/Users/username/dir/data.tsv"
- The
readtable()
command is used to read the data from the source. The data is read in the form of a Julia DataFrame:data = readtable(s)
Data can be written to TSV files from a Julia DataFrame using the following steps:
- Create a data structure with some data inside it. For example, let's create a two-dimensional dataframe like the one we created in the previous example:
using DataFrames df = DataFrame(A = 1:10, B = 11:20)
- Now, the dataframe, which we created in Step 1, can be exported to an external TSV file using the following command:
writetable("data.csv",df)
The writetable()
command is clever enough to make out the format of the file from the filename extension.
推薦閱讀
- Advanced Machine Learning with Python
- MySQL 8 DBA基礎教程
- 表哥的Access入門:以Excel視角快速學習數據庫開發(第2版)
- 劍指MySQL:架構、調優與運維
- iOS開發實戰:從入門到上架App Store(第2版) (移動開發叢書)
- Learning VMware vSphere
- Hacking Android
- WildFly Cookbook
- Mastering Node.js
- HTML5 and CSS3:Building Responsive Websites
- PHP面試一戰到底
- Learning PowerShell DSC(Second Edition)
- JSP項目開發情境教程
- jQuery Mobile從入門到精通
- SQL Server 2014從入門到精通