Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7557221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:04:32+00:00 2026-05-30T12:04:32+00:00

I have following CSV data: 10,11,12.34 I can parse this using CSV from the

  • 0

I have following CSV data:

10,11,12.34

I can parse this using CSV from the standard library, and have the values converted from strings to numbers:

require 'csv'
CSV.parse( "10,11,12.34" )
=> [["10", "11", "12.34"]] 
CSV.parse( "10,11,12.34", {:converters => [:integer,:integer,:float]} )
=> [[10, 11, 12.34]]

I don’t want to convert column 1, I’d just like that left as a string. My guess was I could omit a value from the converters array, but that didn’t work:

CSV.parse( "10,11,12.34", {:converters => [nil,:integer,:float]} )
NoMethodError: undefined method `arity' for nil:NilClass
    from /home/ian/.rvm/rubies/jruby-1.6.6/lib/ruby/1.9/csv.rb:2188:in `convert_fields'
    from org/jruby/RubyArray.java:1614:in `each'
    from /home/ian/.rvm/rubies/jruby-1.6.6/lib/ruby/1.9/csv.rb:2187:in `convert_fields'
    from org/jruby/RubyArray.java:2332:in `collect'
    from org/jruby/RubyEnumerator.java:190:in `each'
    from org/jruby/RubyEnumerator.java:404:in `with_index'
    from /home/ian/.rvm/rubies/jruby-1.6.6/lib/ruby/1.9/csv.rb:2186:in `convert_fields'
    from /home/ian/.rvm/rubies/jruby-1.6.6/lib/ruby/1.9/csv.rb:1923:in `shift'
    from org/jruby/RubyKernel.java:1408:in `loop'
    from /home/ian/.rvm/rubies/jruby-1.6.6/lib/ruby/1.9/csv.rb:1825:in `shift'
    from /home/ian/.rvm/rubies/jruby-1.6.6/lib/ruby/1.9/csv.rb:1767:in `each'
    from org/jruby/RubyEnumerable.java:391:in `to_a'
    from /home/ian/.rvm/rubies/jruby-1.6.6/lib/ruby/1.9/csv.rb:1778:in `read'
    from /home/ian/.rvm/rubies/jruby-1.6.6/lib/ruby/1.9/csv.rb:1365:in `parse'
    from (irb):25:in `evaluate'

In fact I haven’t been able to find any way of specifying that I’d like the first column to be left unconverted. Any suggestions?


Update

I think I misunderstood the design intention for :converters. It’s not a 1:1 mapping by column, but a list of converters to be applied (I think) to all values. I’m not sure, the docs aren’t too clear. So the more general question is: How do I convert some columns in my CSV, and not others?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T12:04:33+00:00Added an answer on May 30, 2026 at 12:04 pm

    The documentation says these options aren’t specified per column, but are instead a list of converters that will be applied to all columns.

    Example:

    CSV.parse("10,11,13,12.34", { :converters => [lambda{|s|s.to_s + 'x'}] })
    # => [["10x", "11x", "13x", "12.34x"]] 
    

    Since the CSV module is eager to convert everything it can, you may as well shift back any columns you want using .to_s or use the :unconverted_fields option to save the original values and allow access to them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want the following functionality using php I have a csv file. Each file
I have the following data in a CSV file. 2454,dum my 12345,dummy 300001,du m
I have a particular csv file with the following data: uid Business Area employeeNumber
I have the following PHP script which reads from two CSV files, At the
After loading data from a csv into an existing Postgres table, I will have
I have a salesforce I export to CSV using a URL like this https://tapp0.salesforce.com/00OT00000014APi?export=1&enc=UTF-8&xf=csv
I have the following situation. I have a PHP script that imports a CSV
I have the following code: ifstream initFile; initFile.open(D:\\InitTLM.csv); if(initFile.is_open()) { // Process file }
I have a file that contains the following in a csv file; country,region,city,postalCode,metroCode,areaCode I
I have a CSV file which has the following format: id,case1,case2,case3 Here is a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.