puzzler
puzzler

Reputation: 343

Julia DataFrame first row of data is being used as column names

I have csv files that don't have a header:

20150409, 15.47, 15.77, 15.07, 15.15, 31116

So when I make a data frame with the file the first row of data turns into the column names for the data frames. I would like to know how to create the data frame with names for the columns already in place(date,close,high,low,open,volume), or at least how to insert a new row for names and bump the data down into the body of the data frame after creating it.

Thanks to anyone who can help!

SOLUTION

Thanks Ismael, I ended up using:

df = readtable(file,names=   [symbol("date"),symbol("close"),
    symbol("high"),symbol("low"),symbol("open"),symbol("volume")])

Upvotes: 4

Views: 2409

Answers (2)

BoZenKhaa
BoZenKhaa

Reputation: 941

In the latest version of DataFrames.jl, the best way of reading DataFrame from CSV file with a missing header row is

df = CSV.read("file.csv", DataFrame; header=[:col1, :col2, :col3])

When the column names are unknown, use header=0. For reference, here is the list of the CSV.read kwargs.

Upvotes: 1

HarmonicaMuse
HarmonicaMuse

Reputation: 7893

You just need to pass the header = false keyword argument (which defaults to true) to the DataFrames.readtable function, ie:

http://dataframesjl.readthedocs.org/en/latest/io.html#advanced-options-for-reading-csv-files

df = readtable("data", header = false)

Upvotes: 2

Related Questions