Writing Data in Tabular form to Files in Julia
Last Updated :
24 Jun, 2021
Julia is a high level, high performance, dynamic programming language which allows users to load, save, and manipulate data in various types of files for data science, analysis, and machine learning purposes. Tabular data is data that has a structure of a table and it can be easily written into various files like text, CSV, Excel, etc.
To perform such operations on data and files with ease, we add the Queryverse.jl package which provides us ease of use for other useful packages such as Query.jl, FileIO.jl, CSVFiles.jl, etc.
Julia
using Pkg
Pkg.add( "Queryverse" )
|
Writing Tabular Data to Text Files
First, we create a text file using the touch() function.
And now we can open the file and write data into it as shown below.
Julia
f = open ( "geek.txt" , "w" )
write(f, "A B C
1 4 7
2 5 8
3 6 9 ")
close(f)
|
Output:

Writing Tabular Data to CSV Files
DataFrames are used to store data in a tabular form and these DataFrames can be written into CSV or Excel files by using the Queryverse.jl package and the save() function. Queryverse.jl package lets the FileIO.jl package use the CSVFiles.jl package to implement this.
Julia
using Queryverse
df = DataFrame(subject = [ "Physics" , "Chemistry" , "English" ], marks = [ 45 , 62 , 59 ])
df |> save( "marks.csv" )
|

We have successfully written tabular data into a CSV file. The format of the data being written can be changed using various keywords as arguments to the save() function.
delim keyword is used to separate columns in the file with a character that we can specify by equating it to the keyword.
Julia
df |> save( "marks.csv" , delim = ';' )
|

The column names of the DataFrame take up the first row of the file. To change this we can use the header keyword argument and equate it to false to remove the column names in the file.
Julia
df = DataFrame(subject = [ "Physics" , "Chemistry" , "English" ],
marks = [ 45 , 62 , 59 ])
df |> save( "marks.csv" , header = false)
|

When the data is written into a file with the save() function, any text in the data will be represented between double quotes( ” ) and if there is a double quote in the text, a backlash ( \ ) is placed before it for differentiation. We can change these characters used for representation with the quotechar and the escapechar keyword arguments as shown below.
Julia
df = DataFrame(subject = [ "Physics + Chemistry" , "English" ], marks = [ 107 , 59 ])
df |> save( "marks.csv" , quotechar = '+' , escapechar = '/' )
|

Writing Tabular Data to Excel Sheets
The process for writing data into excel sheets is the same as that of CSV files, which has been discussed above, but we have to specify a file with the extension ‘*.xlsx’ instead of a ‘.csv’ in the save() function.
Julia
df = DataFrame(subject = [ "Maths" , "Science" , "Computers" ],
marks = [ 61 , 72 , 49 ])
df |> save( "marks.xlsx" )
|

In the excel file, we can change the name of the sheet in which the data is being written into with the sheetname keyword argument as shown below.
Julia
df |> save( "marks.xlsx" , sheetname = "marks in excel" )
|

In Julia, we can write tabular data not only in the three files discussed above also in various other files like Feather, Stata, SPSS, SAS, etc. The save function is applicable to all these file types. We just have to mention the respective extension (*.feature, *.dta, *.por, *.sav) to the file we want to write into.
Similar Reads
Reading Tabular Data from Files in Julia
Julia is a high level, high performance, dynamic programming language which allows users to load, save, and manipulate data in various types of files for data science, analysis, and machine learning purposes. Tabular data is data that has a structure of a table and it can be easily read from various
3 min read
Importing data from Files in Julia
Julia supports File Handling in a much easier way as compared to other programming languages. Various file formats can easily be loaded in our Julia IDE. Most of the file extension packages are loaded into the package, named Pkg in Julia. This basically adds the package needed to load data of differ
5 min read
Write Data to Text Files in MATLAB
Writing data to a text file means creating a file with data that will be saved on a computer's secondary memory such as a hard disk, CD-ROM, network drive, etc. fprintf() function is used to write data to a text file in MATLAB. It writes formatted text to a file exactly as specified. The different e
3 min read
Reading Tabular Data from files in R Programming
Often, the data which is to be read and worked upon is already stored in a file but is present outside the R environment. Hence, importing data into R is a mandatory task in such circumstances. The formats which are supported by R are CSV, JSON, Excel, Text, XML, etc. The majority of times, the data
4 min read
Storing Output on a File in Julia
Julia provides a vast library to store and save the output in multiple file formats. We can store the output in various forms such as CSV(comma-separated value) or in Excel or just simply a text file. Storing Data on Text FileUsing open() function In order to store the data in a text file, we need t
4 min read
Working with Text Files in Julia
Julia is Programming Language that is fast and dynamic in nature (most suitable for performing numerical and scientific applications) and it is optionally typed (the rich language of descriptive type and type declarations which is used to solidify our program) and general-purpose and open-sourced. J
4 min read
Working with DataFrames in Julia
A Data frame is a two-dimensional data structure that resembles a table, where the columns represent variables and rows contain values for those variables. It is mutable and can hold various data types. Julia is a high performance, dynamic programming language which has a high-level syntax. The Data
7 min read
How to Write Entire Dataframe into MySQL Table in R
In this article, we are going to learn how to write the entire data frame into a MySQL table in R programming language. To perform this task we need some basic requirements which are listed below: Install MySQLInstall R StudioBasic knowledge of SQL queries. Using SQL queries create a database "gfg_d
3 min read
Writing to CSV files in R
For Data Analysis sometimes creating CSV data file is required and do some operations on it as per our requirement. So, In this article we are going to learn that how to write data to CSV File using R Programming Language. To write to csv file write.csv() function is used. Syntax: write.csv(data, pa
1 min read
Writing to Files in R Programming
R programming Language is one of the very powerful languages specially used for data analytics in various fields. Analysis of data means reading and writing data from various files like excel, CSV, text files, etc. Today we will be dealing with various ways of writing data to different types of file
2 min read