Join Kevin Skoglund for an in-depth discussion in this video CSV to hashes, part of Ruby: Files, Formats, Templates.
- [Instructor] In this movie, I want to touch…on something that frequently comes up…when working with CSV files, and that is…how to take CSV values and turn them into hashes.…The problem is because the header row…of a CSV file contains all of the labels,…and it's not repeated again for each row after that,…it's just contained at the very top.…After that, we only have values.…But hashes are structured differently,…hashes use labels as keys for each value,…every time we have another hash, that is,…it's repeated in each hash.…
So what we need is a way to efficiently match up the labels…with the values in each row.…And Ruby gives us a handy way to do that.…The first thing I would suggest is…to take the header row that you've got,…and make it into suitable labels.…There's a number of different ways you could do that,…here's a simple one that just downcases everything…that's in the header item,…and replaces all the spaces with underscores.…You could also do more substitutions,…or you could turn it into a symbol if you wanted,…
Author
Released
2/7/2019- File system basics
- Writing to and reading from files
- Renaming, deleting, and copying files
- Creating and editing directories
- Working with common data formats
- ERB templating
Skill Level Beginner
Duration
Views
Related Courses
-
Code Clinic: Ruby
with Kevin Skoglund5h 42m Intermediate -
Ruby: Classes and Modules
with Kevin Skoglund3h 1m Beginner -
Ruby on Rails 5 Essential Training
with Kevin Skoglund10h 21m Beginner -
Ruby: Testing with RSpec
with Kevin Skoglund6h 13m Intermediate
-
Introduction
-
1. The File System
-
Input/output basics3m 36s
-
File system basics3m 55s
-
Types of file paths6m 5s
-
File permissions2m 23s
-
-
2. Work with Files
-
Access files5m 41s
-
Write to files4m 21s
-
Read from files6m 26s
-
File pointer4m 48s
-
Read or write an entire file4m 36s
-
Rename, delete, copy3m 53s
-
Examine file details4m 8s
-
Challenge: List maker7m 12s
-
Solution: List maker7m 8s
-
-
3. Work with Directories
-
Create directories5m 46s
-
Change directories3m 39s
-
Entries4m 53s
-
Glob5m 43s
-
Challenge: Multi-list maker7m 45s
-
Solution: Multi-list maker6m 53s
-
-
4. Common Data Formats
-
CSV6m 49s
-
CSV to hashes3m 13s
-
YAML5m 56s
-
JSON4m 2s
-
XML2m 4s
-
-
5. ERB Templating
-
Embed Ruby6m 20s
-
Binding4m 53s
-
Template files4m 50s
-
Challenge: Mail merge3m 50s
-
Solution: Mail merge4m 11s
-
-
Conclusion
-
Next steps36s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: CSV to hashes