Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Read by thought-leaders and decision-makers around the world. Phone Number: +1-650-246-9381 Email: [email protected]
228 Park Avenue South New York, NY 10003 United States
Website: Publisher: https://towardsai.net/#publisher Diversity Policy: https://towardsai.net/about Ethics Policy: https://towardsai.net/about Masthead: https://towardsai.net/about
Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Founders: Roberto Iriondo, , Job Title: Co-founder and Advisor Works for: Towards AI, Inc. Follow Roberto: X, LinkedIn, GitHub, Google Scholar, Towards AI Profile, Medium, ML@CMU, FreeCodeCamp, Crunchbase, Bloomberg, Roberto Iriondo, Generative AI Lab, Generative AI Lab Denis Piffaretti, Job Title: Co-founder Works for: Towards AI, Inc. Louie Peters, Job Title: Co-founder Works for: Towards AI, Inc. Louis-François Bouchard, Job Title: Co-founder Works for: Towards AI, Inc. Cover:
Towards AI Cover
Logo:
Towards AI Logo
Areas Served: Worldwide Alternate Name: Towards AI, Inc. Alternate Name: Towards AI Co. Alternate Name: towards ai Alternate Name: towardsai Alternate Name: towards.ai Alternate Name: tai Alternate Name: toward ai Alternate Name: toward.ai Alternate Name: Towards AI, Inc. Alternate Name: towardsai.net Alternate Name: pub.towardsai.net
5 stars – based on 497 reviews

Frequently Used, Contextual References

TODO: Remember to copy unique IDs whenever it needs used. i.e., URL: 304b2e42315e

Resources

Take our 85+ lesson From Beginner to Advanced LLM Developer Certification: From choosing a project to deploying a working product this is the most comprehensive and practical LLM course out there!

Publication

Data Engineering Using Julia Lang
Latest   Machine Learning

Data Engineering Using Julia Lang

Last Updated on July 26, 2023 by Editorial Team

Author(s): Vivek Chaudhary

Originally published on Towards AI.

The objective of this blog is to understand how to build a Data Engineering pipeline using Julia Lang. There are a lot of blogs on the internet that talk about the theory of DE, and here I am going to talk CODE, less theory more code.

Import necessary libraries and dataset

using CSV
using DataFrames
using Dates
#load the datasets into memory
emp_df = CSV.read("D:\\Julia\\emp.csv", DataFrame)
print(typeof(emp_df))
#first()to access top 5 records
first(emp_df,5)
dept_df = CSV.read("D:\\Julia\\dept.csv", DataFrame)
print(typeof(dept_df))
first(dept_df,5)

Data operations

  1. Filter records
#filter out records for deptno=30
dept30=filter(row ->row[β€œDEPTNO”] == 30,emp_df)
dept30
#row is a keyword in julia via we can access the column names
#filter multiple conditions
filter(row ->row.SAL> 500 && row.SAL <=1800,emp_df)

2. Sort records

srt_df= sort(emp_df, order(:DEPTNO, rev=false))
first(srt_df,7)

3. Group & Aggregations

#create a seperate small subset for groupby ops
group_df= select(emp_df,”DEPTNO”,”SAL”)
first(group_df,7)
#groupby creates a grouped dataframe other than normal dataframe, somewhat similar to pandas groupby
typeof(gd)
#access group information using array indexes
println(gd[1])
println(gd[2])
println(gd[3])

Aggregations

using Statisticsprintln(β€œsum of sal deptwise β€œ,combine(gd, :SAL => sum))
println(β€œ β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€œ)
println(β€œavg of sal deptwise β€œ,combine(gd, :SAL => mean))
println(β€œmax of sal deptwise β€œ,combine(gd, :SAL => maximum))
println(β€œ β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€œ)
println(β€œsum of sal deptwise β€œ,combine(gd, :SAL => minimum))

4. Julia UDFs

#WAF to calculate tax of employees and add Tax as derived column in existing dataframe.
#function is the keyword to write a udf
function taxes(sal)
tax=0
if sal>500 && sal<=1250
tax=sal*.125
elseif sal>1250 && sal<=1750
tax=sal*.175
elseif sal>1750 && sal<=2500
tax=sal*.225
elseif sal>2500
tax=sal*.25
else
tax=0
end
end
#create a derived column to add calculated taxesemp_df[!, β€œTaxes”] = taxes.(emp_df.SAL)
first(emp_df,8)

5. Joins

#merge the emp_df with grouped df 
agg_df= innerjoin(emp_df,grp_df, on= :DEPTNO)
first(agg_df,10)

Perform SQL like select on the data frame and write dataset to a CSV file:

CSV.write("D:\\Julia\\empagg_out.csv", 
select(agg_df, "EMPNO", "ENAME", "SAL", "COMM", "DEPTNO","Taxes","SAL_sum" => "SalSum"))

Join emp and dept datasets

inner_df= innerjoin(emp_df,dept_df, on= :DEPTNO)
first(inner_df,8)
out_df=select(inner_df,”EMPNO”,”ENAME”,”SAL”,”COMM”,”DEPTNO”,”DNAME”)
first(out_df,8)
CSV.write(β€œD:\\Julia\\empd_out.csv”, out_df)

Summary:

Β· Read CSV datasets

Β· Data operations: filter, sort, groupby, aggregations, joins.

Β· UDFs and derived column.

Β· Write Julia data frames to CSV files

Thanks to all for reading my blog If you like my content and explanation please follow me on medium and share your feedback, that will always help all of us to enhance our knowledge.

Thanks

Vivek Chaudhary

Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming aΒ sponsor.

Published via Towards AI

Feedback ↓