Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing CSV file in Julia : ArgumentError: provide a valid sink argument, like `using DataFrames; CSV.read(source, DataFrame)`

Tags:

julia

I am new to Julia, when i am trying to import csv file

using CSV
CSV.read("C:\\Users\\...\\loan_predicton.csv")

I am getting below error

Error : ArgumentError: provide a valid sink argument, like `using DataFrames; CSV.read(source, DataFrame)`
like image 637
Zeeshan Avatar asked Nov 30 '20 12:11

Zeeshan


1 Answers

Use:

using CSV
using DataFrames
df = CSV.read("C:\\Users\\...\\loan_predicton.csv", DataFrame)

After you will get some more experience with Julia you will find out that you can read a CSV file into different tabular data formats. That is why CSV.read asks you to provide the type of the output you want to read your data into. Here is a small example:

julia> write("test.csv",
       """
       a,b,c
       1,2,3
       4,5,6
       """)
18

julia> using CSV, DataFrames

julia> CSV.read("test.csv", DataFrame)
2×3 DataFrame
 Row │ a      b      c
     │ Int64  Int64  Int64
─────┼─────────────────────
   1 │     1      2      3
   2 │     4      5      6

julia> CSV.read("test.csv", NamedTuple)
(a = [1, 4], b = [2, 5], c = [3, 6])

and you can see that in the first case you stored the result in a DataFrame, and in the second a NamedTuple.

like image 163
Bogumił Kamiński Avatar answered Jan 03 '23 02:01

Bogumił Kamiński