Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia DataFrames: how do i export a DataFrame

If I've created a DataFrame df, how can I save / export this to my cwd as a .csv file? How can I read it back in? The current ReadTheDocs link is broken.

like image 767
jjjjjj Avatar asked Jan 04 '23 19:01

jjjjjj


1 Answers

Currently it's better to use the CSV.jl package, it's simpler and more efficient in writing DataFrames to files.

Assuming that you already imported the DataFrames package and created the data frame df:

using Pkg
Pkg.add("CSV")

using CSV

# for writing
CSV.write("outputfile.csv",df)

# for reading
new_df = CSV.read("outputfile.csv")

The default delimiter is ,, but it's easily changed with :

CSV.write("outputfile.csv",df,delim='\t')

Note that delim needs to be of type Char and not type String.

like image 155
tpdsantos Avatar answered Jan 13 '23 19:01

tpdsantos