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 has rows, where data for some columns only
I have a .csv file containing 3 columns of data. I need to create
I have a .csv file that contains data for only certain columns in a
I have a large CSV data file -- ~1,444,000 rows of data -- that
I have a CSV file that contains over 80,000 rows and 100 columns. I'm
I have a CSV file with 550,000+ rows. I need to import this data
I have a CSV file with 5 columns and about 2*10 4 rows that
I have a number of images and a CSV data file that I want
I have a csv file with data looking like (see below). I need help
I have some questions about importing data from Excel/CSV File into SQL Server. Let

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.