Julia Tips

Hongtao Hao / 2022-01-12


DataFrames #

  1. Select multiple columns:

Reference

select(df, Between(1, 3), Between(4, 6))
  1. Rename columns

Reference

colnames = ["why", "not"]
rename!(df, Symbol.(colnames))
  1. Delete a row (1st row in the following example)
delete!(df, 1)
  1. Delete a column (1st column in the following example)
select!(df, Not(1))
  1. Drop missing values in some but not all colomns

Reference

dropmissing(df, [:A, :B])
  1. Add a column by concatenating strings

Reference

df[:, :NewColname] = string.(df.first_col, " ", df.second_col)

Vector, Array #

  1. Initialize an empty vector of strings

Reference

t = String[];
push!(t, "Anything")
  1. Export an array to CSV

Reference

using DelimitedFilees
writedlm("FileName.csv", A, ',') 
# A is the array

Last modified on 2022-01-31