Off topic:converting rows into columns and vice versa
2
1
Entering edit mode
6.8 years ago
Ana ▴ 200

I have a table file (including 11 million SNPs) and simply I want to convert rows into columns and column into rows. something like this, this is my unput

7 2 2 0 6  
0 2 0 0 0 
2 2 0 0 2

this is my desired output

7  0  2
2  2  2
2  0  0
0  0  0
6  0  2

normally I can do it so easily with R by using as.data.frame(t(df)), but it does not work with my data set maybe because file is so big! I could find this little Python script but does not work as well

with open('in.txt') as f:
  lis = [x.split() for x in f]

for x in zip(*lis):
  for y in x:
    print(y+'\t', end='')
  print('\n')

when I run it I get this error message

File "./row_to_column_transposition.py", line 8
    print(y+'\t', end='')
                     ^
SyntaxError: invalid syntax

I have tried other ways like awk but it does not give me my desired format! Can someone help me to fix it, I would appreciate that.

table python rows colums • 4.3k views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 2566 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6