julialangHow to create dataframes in JuliaLang?
Dataframes in JuliaLang can be created using the DataFrame type from the DataFrames package.
using DataFrames
# Create a dataframe with 3 columns
df = DataFrame(A = [1,2,3], B = [4,5,6], C = [7,8,9])
# Print the dataframe
println(df)
Output example
3×3 DataFrame
│ Row │ A │ B │ C │
│ │ Int64 │ Int64 │ Int64 │
├─────┼───────┼───────┼───────┤
│ 1 │ 1 │ 4 │ 7 │
│ 2 │ 2 │ 5 │ 8 │
│ 3 │ 3 │ 6 │ 9 │
Code explanation
-
using DataFrames: This imports theDataFramespackage which contains theDataFrametype. -
df = DataFrame(A = [1,2,3], B = [4,5,6], C = [7,8,9]): This creates aDataFrameobject with 3 columns,A,BandC, and 3 rows of data. -
println(df): This prints theDataFrameobject to the console.
Helpful links
More of Julialang
- How to test code in JuliaLang?
- How to use regular expressions in JuliaLang?
- How to create plots in JuliaLang?
- How to work with rational numbers in JuliaLang?
- How to use the println function in JuliaLang?
- How to animate in JuliaLang?
- How to add a legend to a plot in JuliaLang?
- How to work with matrices in JuliaLang?
- How to calculate the mean in JuliaLang?
See more codes...