Created
March 30, 2019 09:10
-
-
Save Santara/aa36fb6f7a1e7c7b9979b3ecc5c2db5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import sys | |
def ssv2csv(tsv_filename): | |
"""Converts tab-separated variables into comma-separated variables. | |
""" | |
f_in = open(tsv_filename, 'r') | |
f_out = open(tsv_filename.split('.')[0]+'.csv', 'w') | |
for line in f_in: | |
csv_line = line.strip().split('\t') | |
f_out.write(','.join(csv_line)+'\n') | |
f_out.close() | |
def rewrite_csv(csv_filename): | |
"""Cleans and rewrites csv. | |
""" | |
f_in = open(csv_filename, 'r') | |
f_out = open(csv_filename.split('.')[0]+'.csv', 'w') | |
for line in f_in: | |
csv_line = line.strip().split(',') | |
f_out.write(','.join(csv_line)+'\n') | |
f_out.close() | |
if __name__=='__main__': | |
# ssv2csv(sys.argv[1]) | |
rewrite_csv(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment