Using to import data from a data input file into a DataFrame

In my homemade function ‘readdata()’ I have:
Data =; delim=‘,’, DataFrame)
where ‘filename’ refers to one of my data inputfiles, named e.g. ‘instance.txt’.
This resulted from my code in julia-1.0.

When I try to run this, ‘Data’ remains empty; I cannot extract data from it.

You are getting keyword arguments and positional arguments mixed up, DataFrame; delim = ',')
1 Like

When I do that I get the following:

Data =, DataFrame; delim=‘,’)

#function read(source, sink=nothing; copycols::Bool=false, kwargs…)
#if sink === nothing
#Data =; delim=‘,’, DataFrame)
#Tables.CopiedColumns(CSV.File(source; kwargs…)) |> sink

What to do with it?

You get 6 comments ?

First you should try this.

I got this comment:

#function read(source, sink=nothing; copycols::Bool=false, kwargs…)
#if sink === nothing
#Data =; delim=‘,’, DataFrame)
#Tables.CopiedColumns(CSV.File(source; kwargs…)) |> sink

type the code here

#function read(source, sink=nothing; copycols::Bool=false, kwargs…)
..#if sink === nothing
....#Data =; delim=’,’, DataFrame)
..#Tables.CopiedColumns(CSV.File(source; kwargs…)) |> sink

I copied the comment (with 6 lines). The indentation and my triple backtics disappeared.

you are not describing the problem you are encountering in your code

After my code line ‘Data =, DataFrame; delim=‘,’)’ Julia inserted 6 lines of code, all commented.
I didn’t know what to do with it, because I don’t understand what these 6 lines do.

When I uncomment them, and try to extract a collumn from Data by ‘x = Data[:1]’ Iget ‘UndefVarError: Data not defined’.

Run the following code:

df = DataFrame(a = [1, 2], b = [3, 4])
CSV.write("file.csv", df)
df_new ="file.csv", DataFrame)

Julia is not inserting those comments anywhere. Some other program might be, an editor maybe?

Exactly how are you running the command?

1 Like

The commented code is broken, it looks like two code fragments randomly pasted together.

in addition, Data[:1] is not valid code either

what you should be getting is

julia> Data[:1]
ERROR: ArgumentError: syntax Data[column] is not supported use df[!, column] instead

Thank you! I’m nearly there, but not quite.
I have 5 collumns in my data file, and the first 4 went through.
So I changed naively [3, 4] into [3, 4, 5], but that didn’t work

Can you share the file? Or at least copy and paste the first few lines?


Works perfectly for me.

Could you also extract the last column?

I run this via VSCode