Skip to content

Instantly share code, notes, and snippets.

@Santara
Created March 30, 2019 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Santara/aa36fb6f7a1e7c7b9979b3ecc5c2db5e to your computer and use it in GitHub Desktop.
Save Santara/aa36fb6f7a1e7c7b9979b3ecc5c2db5e to your computer and use it in GitHub Desktop.
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