fastercsv

Ruby and FasterCSV: converting uneven rows to columns

I have a CSV data file with rows that may have lots of columns 500+ and some with a lot less. I need to transpose it so that each row becomes a column in the output file. The problem is that the rows in the original file may not all have the same number of columns so when I try the transpose method of array I get an `transpose': elemen...

RoR: FasterCSV to hash

I'm really struggling with grasping how to effectively use FasterCSV to accomplish what I want. I have a CSV file; say: ID,day,site test,tuesday,cnn.com bozo,friday,fark.com god,monday,xkcd.com test,saturday,whatever.com I what to go through this file and end up with a hash that has a counter for how many times the first column occur...

Importing a huge csv data file and using the header to access columns using Ruby.

I need to import a huge csv data file (6880 columns) and I need to be able use the column headers to access it. What's the best way? Speed isn't important. Clarity is. ...

Rails: FasterCSV - Unique Occurences

I have my CSV file imported as such: records = FasterCSV.read(path, :headers => true, :header_converters => :symbol) How can I get the unique occurences of my data? For instance, here some sample data: ID,Timestamp test,2008.12.03.20.26.32 test,2008.12.03.20.26.38 test,2008.12.03.20.26.41 test,2008.12.03.20.26.42 test,2008.12.03.20....

FasterCSV: Read Remote CSV Files

I can't seem to get this to work. I want to pull a CSV file from a different webserver to read in my application. This is how I'd like to call it: url = 'http://www.testing.com/test.csv' records = FasterCSV.read(url, :headers => true, :header_converters => :symbol) But that doesn't work. I tried Googling, and all I came up with was...

Generating fields containing newline with Ruby CSV::Writer

I want to make CSV::Writer generate a line break within a quoted string: A,B,"Line Line",C So that the row would display in Excel as: A,B,Line,C Line Is it possible to prevent CSV:Writer from stripping out newlines? If not, would switching to FasterCSV solve this problem? ...

How do you change headers in a CSV File with FasterCSV then save the new headers?

Hi, I'm having trouble understanding the :header_converters and :converters in FasterCSV. Basically, all I want to do is change column headers to their appropriate column names. something like: FasterCSV.foreach(csv_file, {:headers => true, :return_headers => false, :header_converters => :symbol, :converters => :all} ) do |row| put...

How do I import using FasterCSV a row with a name like "Ciarán"?

I am trying to load in my data migration a member database. Quite a few of the names have special characters such as "Ciarán". I've set up a simple example like this: require 'rubygems' require 'fastercsv' FasterCSV.foreach("/Users/developer/Work/madmin/db/data/Members.csv") do |row| puts row.inspect end and I get the following: ...

FasterCSV - raising MalformedCSVError when it shouldn't

Sample data: "iWine","Barcode","Location","Bin","Size","Valuation","Price","StoreName",\ "PurchaseDate","Note","Vintage","Wine","Locale","Country","Region","SubRegion",\ "Appellation","Producer","SortProducer","Type","Color","Category","Varietal",\ "MasterVarietal","Designation","Vineyard","WA","WS","IWC","BG","WE","JR",\ "RH","JG","GV"...

RoR ActiveRecord find_by_sql Question

I want to preface this question by stating that I am fairly new to Ruby development, however, personally, I've dedicated myself to trying to find the answers myself, as opposed to whimsically asking questions on forums. That being said, this is my first official "post", and I have made every attempt to be as accurate and concise in my po...

Import CSV in batches of lines in Rails?

I'm using FasterCSV to import an uploaded file to a model, and it's working great for small files. However when I try to import a large dataset (21,000 lines) it takes ages and I get browser timeouts on the live server. This is my current working code: logcount=0 Attendee.transaction do FCSV.new(file, :headers => true).each do ...

Error with Paperclip / FasterCSV Processing for optional csv upload

Hi, I have a page where a user can import data to the site. either in the form of copy and pasting into a text area from excel, or by uploading a .csv file. The controller checks if a csv has been uploaded - if so it processes this, else it will process the pasted content. (working on the assumption the user will only choose one option...

FasterCSV: columns into an array -- rails

I'm trying to get fastercsv setup so that rather than parsing each row, it will place each column into an multi array. CSV import file: id, first name, last name, age 1, joe, smith, 11 2, jane, doe, 14 Save to array named people: people[0][0] would equal id people[2][1] would equal jane This is what I currently have: url = 'http://u...

How does FasterCSV determine whether or not to add quote?

Hi, When I try to output some data into a text file using FasterCSV, sometimes it adds the quotes to the concatenated string and sometimes it does not. For instance: FasterCSV.generate do |csv| csv << ["E"+company_code] csv << ["A"+company_name] end Both company_code and company_name are Strings and contains data bu...

export to csv using fastercsv and CSV::Writer (Ruby on Rails)

What am I trying to do: export data to csv. I have a form which allows user to select the format (from a drop down menu). So based on the selection of the format the ouput is displayed using a ajax call. Works fine for html but when I select the format as csv I don't see any pop up on the screen (asking to save or open the file) and nei...

Overcoming a basic problem with CSV parsing using the FasterCSV gem

I have found a CSV parsing issue with FasterCSV (1.5.0) which seems like a genuine bug, but which I'm hoping there's a workaround for. Basically, adding a space after the separator (in my case a comma) when the fields are enclosed in quotes generates a MalformedCSVError. Here's a simple example: # No quotes on fields -- works fine F...

fastercsv - save object table in one go (ruby)

I read my csv using the line below data = FCSV.table("test.csv", {:quote_char => '"', :col_sep =>',', :row_sep =>:auto, :headers => true, :return_headers => false, :header_converters => :downcase, :converters => :all} ) QUESTION Can I save object data in the same manner (one line, one go + csv options)? see above I sort the table (s...

Ruby on Rails Moving from CSV to FasterCSV

I currently have the following code to parse a csv file using the standard csv library @parsed_file=CSV::Reader.parse(params[:dump][:file]) @parsed_file.each do |row| #some code end I want to move this to faster csv for the increased speed. Does anyone know the equivalent of the above for FasterCSV? Thanks ...

Proper way to parse this line with FasterCSV?

I have the following line in a CSV file that's giving me issues when parsing: 312,'997639',' 2','John, Doe. "J.D." ',' ','2000 ',' ','Street ','City ','NY','99999','','2010-02-17 19:12:04','2010-02-17 19:12:04'; I'm parsing with the following par...

Exporting large amounts of data using FasterCSV with Rails

I have a controller in Rails that generates CSV reports using FasterCSV. These reports will contain approximately 20,000 rows, maybe more. It takes about 30 seconds or more when creating the csv_string in my implementation below. Is there a better/faster way to export the data? Any way to output the data without having to store it all i...