Exploratory Data Analysis in Julia - GeeksforGeeks

12 Oct, 2020
Exploratory Data Analysis (EDA) is used for achieving a better understanding of data in terms of its main features, the significance of various variables, and the inter-variable relationships. The First step is to explore the dataset.  
Methods to explore the given dataset in Julia:
Using data tables and applying statisticsUsing Visual Plotting techniques on the data
Using data tables and applying statistics
Using Visual Plotting techniques on the data
Step 1: Install DataFrames Package  
For using data tables in Julia, a data structure called Dataframe is used. DataFrame can handle multiple operations without compromising on Speed and Scalability.
Dataframes package can be installed using the following command:
using Pkg
Pkg.add(“DataFrames”)

Step 2: Download the Dataset  
For data analysis, we have used the Iris dataset. It is easily available online.
Step 3: Import Necessary Packages and the Dataset
Let’s first import our DataFrames Package, CSV Package, and load the Iris.csv file of the data set:
Julia
# Using the DataFrames Packageusing DataFrames  # Using the CSV packageusing CSV  # Reading the CSV fileIris = CSV.read(“Iris.csv”)
Output:
Step 4: Quick Data Exploration
Preliminary exploration can be performed on the dataset such as identifying the shape of the dataset using the size function, list of columns using the names function, first n rows using the head function.  
Example:
Julia
# Using the DataFrames Packageusing DataFrames  # Using the CSV packageusing CSV  # Reading the CSV fileIris = CSV.read(“Iris.csv”);  # Shape of Datasetsize(Iris)  # List of columnsnames(Iris)   # First 10 rowshead(Iris, 10)
Output:
Dataframe_name[:column_name] is a basic indexing technique to access a particular column of the data frame.  
Example:
Julia
# Using the DataFrames Packageusing DataFrames  # Using the CSV packageusing CSV  # Reading the CSV fileIris = CSV.read(“Iris.csv”);  # Access particular column of datasetIris[: SepalLength]
Output:
Describe function is used to present the mean, median, minimum, maximum, quartiles, etc of the dataset.
Example:
Julia
# Using the DataFrames Packageusing DataFrames  # Using the CSV packageusing CSV  # Reading the CSV fileIris = CSV.read(“Iris.csv”);  # Using describe function # to get statistics of a datasetdescribe(Iris)  # Using describe function to get# statistics of a particular column in a datasetdescribe(Iris, :all, cols=:SepalLength)
Output:
Visual Exploration in Julia can be achieved with the help of various plotting libraries such as Plots, StatPlots, and Pyplot.
Plots: It is a high-level plotting package that interfaces other plotting packages called ‘back-ends‘. They behave like the graphics engines that generate the graphics. It has a simple and consistent interface.
StatPlots: It is a supporting package used with Plots package consisting of statistical recipes for various concepts and types.
PyPlot: It is used to work with mathplotlib library of Python in Julia.
The above-mentioned libraries can be installed using the following commands:
Pkg.add(“Plots”)  
Pkg.add(“StatPlots”)  
Pkg.add(“PyPlot”)

The distribution of variables in Julia can be performed using various plots such as histogram, boxplot, scatterplot, etc.  
Let’s start by plotting the histogram of SepalLength:
Example:
Julia
# Using the DataFrames Packageusing DataFrames   # Using the CSV packageusing CSV   # Reading the CSV fileIris = CSV.read("Iris.csv");  # Using Plots Package using Plots   # Plot HistogramPlots.histogram(Iris[:SepalLength],                 bins = 50, xlabel = "SepalLength",                             labels = "Length in cm")
Output:
Next, we look at box plots to understand the distributions. Box plot for SepalLength can be plotted by:
Example:
Julia
# Using the DataFrames Packageusing DataFrames   # Using the CSV packageusing CSV   # Reading the CSV fileIris = CSV.read("Iris.csv");  # Using Plots,StatPlots Package using Plots, StatPlots   # Plot BoxplotPlots.boxplot(Iris[:SepalLength],              xlabel = "SepalLength")
Output:
Next, we look at Scatter plot to understand the distributions. Scatter plot for SepalLength can be plotted by:
Example:
Julia
# Using the DataFrames Packageusing DataFrames   # Using the CSV packageusing CSV   # Reading the CSV fileIris = CSV.read("Iris.csv");  # Using Plots package using Plots  # Plot Scatterplotplot(Iris[:SepalLength],      seriestype = :scatter,     title = "Sepal Length")
Output:
Julia Data-science
Julia
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Decision Making in Julia (if, if-else, Nested-if, if-elseif-else ladder)
Get array dimensions and size of a dimension in Julia - size() Method
Exception handling in Julia
Searching in Array for a given element in Julia
Find maximum element along with its index in Julia - findmax() Method
Get number of elements of array in Julia - length() Method
Join an array of strings into a single string in Julia - join() Method
Working with Excel Files in Julia
File Handling in Julia
Getting last element of an array in Julia - last() Method