DataFrames.jl (3) and Pipe

Selecting and transforming columns When selecting variables of a data frame, we do add : to indicate that it’s a variable name. Thus for example, if we want to select column with variable x, we use :x inside select(). First let’s construct some 500 by 3 dimensional data frame called df that contains three columns each of which has name of A, B, and C. using DataFrames df = DataFrame( A=1:2:1000, B= repeat(1:10, inner=50), C= 1:500) Each of below codes produces 500 by 1 dataframe, a data frame that only contains column A....

April 19, 2023 · 2 min · 313 words · Me

DataFrames.jl (2)

Taking a Subset We can subset a dataframe using index. For example we can subset specific columns and rows by following codes. # column subset (subset df to only include column A and C) df[:, [:A, :C]] # row subset (subset df to only include 1st, 3rd, and 5th rows) df[[1,3,5], :] We could also use some selectors such as Not, Between, Colsand All. Following code removes columns whose names match r"x"....

April 12, 2023 · 1 min · 152 words · Me

DataFrames.jl (1)

Create dataframe To create a dataframe, simply use DataFrame function after loding DataFrames.jl. Following code produces a dataframe composed of three variables, A, B, and C, each of which has 500 rows. Each row of column A increments by 2 starting from integer 1. Column B repeats 50 times of each integer starting from 1. Coumn C lists integers from 1 to 500. using DataFrames df = DataFrame(A=1:2:1000, B= repeat(1:10, inner=50), C= 1:500) first, last The first and last functions act as head and tail function in R, which allow us to view the first or the last couple of rows of the dataset....

April 11, 2023 · 2 min · 236 words · Me