Friday, May 3, 2024
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 6918  / 2 Years ago, thu, june 2, 2022, 11:31:06

I have some csv files with too many columns for LibreOffice Calc to open, but only a few rows. If I can transpose the csv file, it should be ok as Calc can deal with very many more rows than columns.


More From » software-recommendation

 Answers
1

A simple python program would do the job (and since this is not really tested: backup you csv file in advance!):



import csv
import sys
infile = sys.argv[1]
outfile = sys.argv[2]

with open(infile) as f:
reader = csv.reader(f)
cols = []
for row in reader:
cols.append(row)

with open(outfile, 'wb') as f:
writer = csv.writer(f)
for i in range(len(max(cols, key=len))):
writer.writerow([(c[i] if i<len(c) else '') for c in cols])


You can save this into a file "my_csv_transposer.py" and call it from the commandline like this:



python my_csv_transposer.py <theinfilename> <theoutfilename>

[#42361] Saturday, June 4, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ickump

Total Points: 234
Total Questions: 124
Total Answers: 111

Location: Jordan
Member since Fri, Apr 8, 2022
2 Years ago
ickump questions
Mon, Aug 16, 21, 08:46, 3 Years ago
Mon, Aug 22, 22, 02:44, 2 Years ago
Sun, Oct 2, 22, 07:13, 2 Years ago
;