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

  • SEARCH
  • Home
  • 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 67417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:15:24+00:00 2026-05-10T19:15:24+00:00

I have a CSV data file with rows that may have lots of columns

  • 0

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:

`transpose’: element size differs (12 should be 5) (IndexError)

Is there an alternative to transpose that works with uneven array length?

  • 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. 2026-05-10T19:15:24+00:00Added an answer on May 10, 2026 at 7:15 pm

    I would insert nulls to fill the holes in your matrix, something such as:

    a = [[1, 2, 3], [3, 4]]  # This would throw the error you're talking about # a.transpose  # Largest row size = a.max { |r1, r2| r1.size <=> r2.size }.size  # Enlarge matrix inserting nils as needed a.each { |r| r[size - 1] ||= nil }  # So now a == [[1, 2, 3], [3, 4, nil]] aa = a.transpose  # aa == [[1, 3], [2, 4], [3, nil]] 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a csv file that looks something like this (actual file has many
So I have a CSV that contains a filename and a file's contents. The
I have an unnormalized events-diary CSV from a client that I'm trying to load
We have a Swing app that processes relatively large amounts of data. For instance
am exporting huge data to excel using php. i change that to csv and
I'm experimenting with using the pg_bulkload project to import millions of rows of data
My boss has a habit of performing queries on our databases that return tens
I have a pretty simple question (and these are typically the ones I spend
I volunteer for a local non-profit that gives out toys and food during the
I'm learning SSIS and this seems like an easy task but I'm stuck. I

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.