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.
first(df, 10)
Output:
10×3 DataFrame
Row │ A B C
│ Int64 Int64 Int64
─────┼─────────────────────
1 │ 1 1 1
2 │ 3 1 2
3 │ 5 1 3
4 │ 7 1 4
5 │ 9 1 5
6 │ 11 1 6
7 │ 13 1 7
8 │ 15 1 8
9 │ 17 1 9
10 │ 19 1 10
last(df, 10)
Output:
10×3 DataFrame
Row │ A B C
│ Int64 Int64 Int64
─────┼─────────────────────
1 │ 981 10 491
2 │ 983 10 492
3 │ 985 10 493
4 │ 987 10 494
5 │ 989 10 495
6 │ 991 10 496
7 │ 993 10 497
8 │ 995 10 498
9 │ 997 10 499
10 │ 999 10 500
Reference
https://dataframes.juliadata.org/stable/man/working_with_dataframes/