#!/usr/bin/env python
import click
import pandas as pd
import csv
import re
@click.group()
@click.option("--tf_output", "-to", default=None)
@click.pass_context
def group(ctx, tf_output):
pass
@group.command()
@click.argument("src")
@click.pass_context
def ltsv2csv(ctx, src):
"""LTSV to CSV"""
output = f"{src}.csv"
def get_line_dict(line):
return dict(re.search(r"^([^\:]+)\:(.*)$", i).groups() for i in line)
with open(src) as f:
data = pd.DataFrame(map(get_line_dict, csv.reader(f, delimiter="\t")))
data.to_csv(output, index=False)
if __name__ == "__main__":
group()
Created
October 11, 2024 07:56
-
-
Save hdknr/eb0e057830beda5efc3e5590c54e8e4f to your computer and use it in GitHub Desktop.
ltsv
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment