Asset Classes

Free investment financial education

Language

Multilingual content from IBKR

Close Navigation
Learn more about IBKR accounts
Data Manipulation and Visualization Techniques in Julia – Part II

Data Manipulation and Visualization Techniques in Julia – Part II

Posted April 20, 2022 at 8:30 pm

Anshul Tayal
QuantInsti

Learn how to create new dataframes with Part I.

Basic mathematical operations

As discussed in my previous post, basic arithmetic operations can be performed on individual columns.

# Subtraction
df_2.a - df_2.b

subtraction.jl hosted with ❤ by GitHub

10-element Vector{Float64}:

-0.5474996670806442
 0.5174063588946236
-0.564150142575268
 0.12873854328766576
 0.2741519215981265
 0.20241852864291987
 0.09324017568958975
-0.41716724316286524
 0.2693306887583933
-0.5967498723478988

You’ll have to use the “.” operator for element-wise division.

df_2.["a"] ./ df_2["b"] 

elementwise operation.jl hosted with ❤ by GitHub

10-element Vector{Float64}:

0.06754620232737023
3.013387340201863
0.4169119702423886
1.2293455286486041
1.4462537614868343
8.482279426917298
1.1103752688515762
0.21238611891693882
3.1244976300403002
0.38733760512833965

Basic operations

Rearranging columns

r” is a regex search string. Here, any column with a string “work” will be selected and moved to the first place. You can write the full column name as well.

## Method to rearrange columns in a dataframe
select!(df_1, r"work", :)

rearranging columns.jl hosted with ❤ by GitHub

work experiencenameteam
Int64StringString
15VivekEPAT
8VirajMarketing
7RohanSales
10IshanQuantra

Adding a new column in a dataframe

Here we add another column, “c”, to the dataframe df_2.

df_2.c = rand(10)
df_2

adding new column.jl hosted with ❤ by GitHub

abc
Float64Float64Float64
0.8450110.7203060.962749
0.6476650.04090360.10846
0.4272670.2213690.197592
0.4136420.3748320.967406
0.4779940.1184610.0233091
0.08490060.1576790.936764
0.04774050.8453320.296003
0.5189090.1593050.514714
0.934990.2595790.620951
0.600340.1159110.0224133

Dataframe-to-matrix conversion

Matrix(df_2)

dataframe to matrix.jl hosted with ❤ by GitHub

10×3 Matrix{Float64}:

0.0396604  0.58716    0.741712
0.774389   0.256983   0.429361
0.403371   0.967521   0.989583
0.690069   0.56133    0.50599
0.888493   0.614341   0.152574
0.229472   0.0270531  0.932589
0.937996   0.844756   0.0745573
0.112492   0.52966    0.712178
0.396105   0.126774   0.397762
0.377277   0.974027   0.685073

Visit QuantInsti to read the full article: https://blog.quantinsti.com/data-manipulation-visualization-using-julia/.

Disclosure: Interactive Brokers

Information posted on IBKR Campus that is provided by third-parties does NOT constitute a recommendation that you should contract for the services of that third party. Third-party participants who contribute to IBKR Campus are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.

This material is from QuantInsti and is being posted with its permission. The views expressed in this material are solely those of the author and/or QuantInsti and Interactive Brokers is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to buy or sell any security. It should not be construed as research or investment advice or a recommendation to buy, sell or hold any security or commodity. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

IBKR Campus Newsletters

This website uses cookies to collect usage information in order to offer a better browsing experience. By browsing this site or by clicking on the "ACCEPT COOKIES" button you accept our Cookie Policy.