-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtranspose.py
36 lines (24 loc) · 886 Bytes
/
transpose.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
"""
Read a tsv file and transpose it.
"""
import os
import sys
import argparse
import pandas as pd
from roblib import bcolors
__author__ = 'Rob Edwards'
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=' ')
parser.add_argument('-i', '--input', help='input file', required=True)
parser.add_argument('-o', '--output', help='output file', required=True)
parser.add_argument('-s', '--sep', help='separator (default=tab)', default="\t")
parser.add_argument('-v', help='verbose output', action='store_true')
args = parser.parse_args()
if args.v:
print(f"{bcolors.GREEN}Reading {args.input}{bcolors.ENDC}")
df = pd.read_csv(args.input, sep=args.sep)
dft = df.T
if args.v:
print(f"{bcolors.GREEN}Writing {args.output}{bcolors.ENDC}")
dft.to_csv(args.output, sep=args.sep)