2

I started with a CSV file, which I read into a CSV::Table, 104 columns, and wanted to filter it down to three:

filtered_data = csv.map { |row| row.fields(:x,:y:,:z) }

I then want to convert x from epoch time to regular GMT. I did this using:

filtered_data.each do |thing|
  thing[0] = Time.at(thing[0]).to_datetime
end

Thus yielding:

[[converted_x, y,z],[converted_x, y, z]] 

Is there another way of doing this using the map function or is this the preferred solution?


Using Jeremy's answer I now have:

filtered_data.map { |x,y,z| [Time.at(x).to_datetime,y,z] } 

And then further filtering using reject:

filtered_data.reject { |x,y,z| [x,y, z == '\\ '] }
0

1 Answer 1

2
filtered_data.map do |x, y, z|
  [Time.at(x).to_datetime, y, z]
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.