Closed parthm closed 7 years ago
You can use whatever header converters you want by passing options to the standard Ruby CSV parser (http://ruby-doc.org/stdlib-2.0.0/libdoc/csv/rdoc/CSV.html#method-i-header_converters). Here's one way to get what you want:
df = Daru::DataFrame.from_csv myfile, { headers: true, header_converters: CSV::HeaderConverters[:symbol] }
Ah. Perfect. Thanks for pointing it out @gnilrets . I was not aware of that.
I think problem is solved. Closing.
While reading a CSV, it might be convenient to optionally have headers be symbols instead of strings. As of now I just read the CSV and convert the convert the headers using the code below.
This allows us to conveniently access vector content
v[:foo]
and dataframe vectorsdf[:bar]
which arguably is a more ruby like way to access values. This is intuitive as symbols are frequently used as keys for ruby data structures. Perhaps a flag likesymbol_headers=true|false
can be supported in thefrom_csv
method. While writing, they symbols are obviously stored as strings and nothing changes at that front.