using CSV,DataFrames
data1=DataFrame(CSV.File(“D:\\documemt\\julia\\aaa.csv”))
a=[1,1,2,2,1,2]
index=findall(in(1),a)
Data=data1.colum1[index]
CSV.write(“BBBB.csv”,Data)
The contents of the aaa. CSV file are as follows
colum1
2018/12/30 0:00
2018/12/30 1:00
2018/12/30 2:00
2018/12/30 3:00
2018/12/30 4:00
2018/12/30 5:00
2018/12/30 6:00
2018/12/30 7:00
2018/12/30 8:00
2018/12/30 9:00
The last line of the code reports an error, as follows:
LoadError: ArgumentError: ‘Array{String,1}’ iterates ‘String’ values, which doesn’t satisfy the Tables.jl AbstractRow interface
How do I export the Data’s elements to a CSV file?
Apologies, it was indeed slightly wrong - you want either (column1 = Data, ) (note the trailing comma) or (; column1 = Data) (note the leading semicolon) to construct the NamedTuple.
Glad you got it to work! A couple of other general hints if I may:
The CSV.jl package has brought back the CSV.read function, so you can do CSV.read("myfile.csv", DataFrame) to read a file into a DataFrame
If you know you want to write a table back out to csv, it’s probably easier to continue operating on a DataFrame rather than pulling out a Vector and creating a NamedTuple from that - I would probably do data1[index, [:column1]]. Note the column index is passed in [] brackets, making it an Array{Symbol ,1} (rather than just a Symbol). Doing so means the indexing operation returns a DataFrame.