Created
November 30, 2018 08:52
-
-
Save search5/f89b02456dc8b0999448bb762639c0fb to your computer and use it in GitHub Desktop.
This file contains hidden or 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 click | |
import csv | |
@click.group() | |
def cli(): | |
pass | |
@cli.command() | |
def duplicate(): | |
'''중복 걸러내기''' | |
def minimum_item(part_name, records): | |
filled = tuple(filter(lambda x: x[1] == part_name, records)) | |
if len(filled) > 1: | |
return min(map(lambda x: int(x[0].replace(',','')), filled)) | |
else: | |
return filled[0][0] | |
result = [] | |
csv_filename = 'file.csv' | |
with open(csv_filename, newline='') as csvfile: | |
item_reader = csv.reader(csvfile, delimiter='\t') | |
records = tuple(item_reader) | |
for row in records: | |
new_idx = minimum_item(row[1], records) | |
result.append('{0}\t{1}'.format(new_idx, '\t'.join(row))) | |
for row in result: | |
print(row) | |
@cli.command() | |
def join(): | |
'''단순병합''' | |
def k(arg): | |
return "/".join(filter(lambda x: len(x.strip()) > 0, arg)) | |
with open('file2.csv', newline='') as csvfile: | |
item_reader = csv.reader(csvfile, delimiter='\t') | |
for item in item_reader: | |
print(k(item)) | |
if __name__ == '__main__': | |
cli() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment