Operations on the Entire Dataframe

Here are some selected operations on the entire dataframe.

Meta Data

Get the Number of rows and columns of a dataframe df using

size(df)

Get details about the columns of the dataframe df

describe(df)    

../assets/images/img_blog/Julia/Julia_describe.png
Get the columns, their types and some statistics, when you describe the Julia dataframe.

Basic Arithmetics

Let’s define a new, small dataframe df1. A dataframe based on a 2x2 unity matrix might do.

df1 = DataFrame(A = [1, 0], B = [0, 1] )

Multiply with a scalar

Multiply the dataframe with pi.
Subtract the square root of 2.

df2 = df1 .* π
df2 = df1 .- sqrt(2)

Mind the broadcasting operator!

Matrix operations

A matrix contains the body of a dataframe. Some operations on a Julia dataframe are not available, but can be retrieved by extracting this matrix and then re-assembling the dataframe.

Transpose

There is no built-in transpose command in Julia Dataframes. You need to extract the matrix, transpose the matrix and re-built a dataframe.

You can get the matrix, ma, from the dataframe with the matrix command

ma = Matrix(df)

Then, you transpose the matrix

mat = transpose(ma)
mat = ma'

The matrix mat holds the transposed matrix.

Finally, you need to get back to a new dataframe, dfT,

dfT = DataFrame(mat, :auto)

and to adjust the column names later. Mind the second parameter (“auto”) which is required in higher versions of DataFrames.

Invert

Do the same as for transpose, but invert the matrix.

mai = inv(ma)
Copyright 2021-2022