CSV, DataFrame read data file with string and Float64 columns

I would like to read this data file [first row is title], containing string in the first column, and float64 in the following columns,
"
id aMphi aMoctet a*Mdecuplet
A651 0.27507 0.00087 0.6715 0.0044 0.8033 0.0063
A652 0.2140 0.0010 0.5842 0.0041 0.689 0.013
A650 0.1835 0.0013 0.5469 0.0054 0.663 0.013
"

I try to use the following commander to read the data,
CSV.read(“CLS_2023_Tab17.dat”, DataFrame; header=true)

however, I got a 3X1 “string” matrix, how can I get 3X7 matrix?

If possible, can i skip the first column, and just read the Float64 in the dataframe, and have a 3X6 Float64 matrix?

If the column delimiter is a space you can try this:

df=CSV.read("CLS_2023_Tab17.dat", DataFrame; header=true, delim=" ", drop=[1])

You get a warning because your header line only has 4 entries.

1 Like

Thanks! the delim=" " does not work in this case. Because there are several random spaces between columns. Then, I change the datafile by including the “,” between columns, then works for my case.

df=CSV.read(“CLS_2023_Tab17.dat”, DataFrame; header=true, delim=“,”, drop=[1])

Or you use ignorerepeated like :

julia> df=CSV.read("CLS_2023_Tab17.dat", DataFrame;
       header=true, delim=" ", drop=[1], ignorerepeated=true)

Check out:

julia> ?CSV.read
1 Like