Julia – DataFrames
Data Frames in Julia is an alternative for Pandas Package in Python. Data Frames represent the data in a tabular structure. We can manipulate the data using these data frames. Various operations can be done on the Data frames for altering the data and making row-column transformations.
Data Frames are mainly used and created for accessing the data in a row-column manner.
Similarly to the python installation of packages, Julia also includes the importing methods.
Installation of required packages:
Julia can be programmed using Jupyter notebooks or Atom software. To install data frame package in Julia, please use the following commands:
using Pkg Pkg.add("DataFrames")
Momentarily, DataFrame in Julia is covered in the program by importing them by the keyword argument “using”. The data is represented in a row-column manner and manipulated using the operations that we come across in later read. To import DataFrames package in your code, use the following command:
Creation of DataFrames
Data frames in Julia are created with the use of pre-defined DataFrame() function. It takes values and column names as argument and creates a data frame.
As explained above, we got to know all about creating a data frame in Julia. Let us understand the structure of the data frame created above by understanding the row-column structured data.
The columns here are I, II, and III they act as user-defined keywords for representing the columns.
- The Column “I” comprises of float values.
- The Column “II” includes an integer value and a missing value.
- The Column “III” holds String characters.
Accessing columns of a Data frame
In Julia, columns can be accessed through “data.column” here ‘data’ is our variable element in which we have created our DataFrame and ‘column’ is the user-defined keyword for our DataFrame column.
First, let us create a data frame to perform further operations on it
Let us now look at the examples of accessing the column elements using some of the operations.
We have accessed the second column in the dataframe2 object created and stored the retrieved column in the ‘op1’ variable.
As we can compare with the above code in which we accessed column two. Similarly, we can also access any column by including them in double-quotes.
The syntax denotes the accessing of the first column
The above code represents two basic functions in Julia ‘names’ and ‘propertynames’.
- In Julia, the function ‘names’ display the column names in the dataframe created by the user.
- The function ‘propertynames’ display the column names as symbols using ‘ : ‘ .
Adding elements to the DataFrame
Here, we are creating a data frame with no information instead declaring the datatype of the columns.
Now that we have created a Data Frame and stored in a variable called ‘data’.
- The first column includes the data of integer datatype.
- The second column includes the data of String datatype.
Let us now push the data into the DataFrame columns by taking action with the ‘push()‘ function.
Renaming the columns of the DataFrame
In Julia, the renaming operation is done by a function rename!(). This function changes the name or the keyword of a column which is already been listed by the user.
Creating Subsets of a Data Frame
Subsets can be easily created by breaking the data frame into Head and Tail. The head of a Data frame can be displayed with the use of head() function and the tail can be displayed with the use of tail() function.
This function illustrates the head part of the DataFrame we created.
The head function returns us the head portion or the top part of our DataFrame.
The tail function illustrates the tail part of the DataFrame created.
For the DataFrame created we have worked on the tail operation. The function displays bottom-most values in the data frame.
Deleting Rows and Columns of the DataFrame
The delete operation in Julia is performed using the delete!() function. This function takes data frame name and the row or column to be deleted as argument and performs the deletion.
As declared in the above code we performed the delete operation on the ‘dataframe2’ and deleted the 4th row.
Now that we have come across deleting a row using the function ‘delete!()‘.
Let us now eliminate a column element:
In the above code, we have accessed the columns of Dataframe2 excluding the ‘II’ column.