-
-
Save ohlol/d5da698c559bf096d096c92927a81d5e to your computer and use it in GitHub Desktop.
Create a random sample of records from a JSON Lines file
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 json | |
import math | |
with open("data/repos.jsonl") as f: | |
records = [json.loads(x) for x in f] | |
count = len(records) | |
sample_count = math.ceil(.01*count) | |
sample_records = random.sample(records, sample_count) | |
with open("data/repos_sample_0.01.jsonl", "w") as f: | |
for record in sample_records: | |
f.write(json.dumps(record) + "\n") | |
print("Sampled {} records from {} original records.".format( | |
sample_count, | |
count | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment