diff options
| author | adamhrv <adam@ahprojects.com> | 2018-11-04 21:54:00 +0100 |
|---|---|---|
| committer | adamhrv <adam@ahprojects.com> | 2018-11-04 21:54:00 +0100 |
| commit | 9bcba0d02aafb34a5a9ca3db2f894f1fc95401c0 (patch) | |
| tree | 3dcaf94563498c15b56d51efc62750d0be72e01a /check-counts.py | |
| parent | ef45f3c93ffd39b57ee56db74a95f9d2dae074a8 (diff) | |
| parent | 0dc3e40434c23e4d48119465f39b03bf35fb56bd (diff) | |
.
Diffstat (limited to 'check-counts.py')
| -rw-r--r-- | check-counts.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/check-counts.py b/check-counts.py new file mode 100644 index 00000000..4fed4494 --- /dev/null +++ b/check-counts.py @@ -0,0 +1,39 @@ +import os +import sys +import csv +from math import ceil +import subprocess +import random + +import click + +@click.command() +def check_counts(): + """Split a CSV into groups.""" + mypath = './datasets/scholar/entries/' + onlyfiles = [f for f in os.listdir(mypath) if os.path.isfile(os.path.join(mypath, f))] + recs = [] + for f in onlyfiles: + with open(os.path.join(mypath, f), 'rb') as f: + reader = csv.reader(f, delimiter='|') + print f + print repr(reader) + lines = list(reader) + rec = lines[0] + recs.append(rec) + + out_fn = './datasets/scholar_entries.csv' + write_csv(out_fn, keys=None, chunk=recs) + +# Write a CSV +def write_csv(fn, keys, chunk): + print(fn) + with open(fn, 'w') as f: + writer = csv.writer(f) + if keys is not None: + writer.writerow(keys) + for row in chunk: + writer.writerow(row) + +if __name__ == '__main__': + check_counts() |
