Download pool/shard001/Python/0009122_json2csv.py from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard001/Python/0009122_json2csv.py
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/pool/shard001/Python/0009122_json2csv.py
-
curl -L -o 0009122_json2csv.py https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard001/Python/0009122_json2csv.py
1.1 kB
| #!/usr/bin/env python | |
| #Convert json array file in csv file | |
| #import | |
| import ijson | |
| import csv | |
| import time | |
| import sys | |
| import os | |
| import datetime | |
| os.chdir('/home/julien_ha/data') | |
| #Start timer | |
| start_time = time.time() | |
| input_file = sys.argv[1] | |
| output_file = input_file.replace('.json','.csv') | |
| #Parse json file | |
| f1 = open(input_file) | |
| d1 = [] | |
| for item in ijson.items(f1, "item"): | |
| d1.append(item) | |
| f = csv.writer(open(output_file, "wb+")) | |
| # Write CSV Header, If you dont need that, remove this line | |
| f.writerow(["blockHash","blockNumber","from","gas","gasPrice","hash","input","nonce","timestamp","to","transactionIndex","value"]) | |
| for t in d1: | |
| f.writerow([t["blockHash"], | |
| t["blockNumber"], | |
| t["from"], | |
| t["gas"], | |
| t["gasPrice"], | |
| t["hash"], | |
| t["input"], | |
| t["nonce"], | |
| t["timestamp"], | |
| t["to"], | |
| t["transactionIndex"], | |
| t["value"] | |
| ]) | |
| #Print time duration | |
| print("Done in --- %s seconds ---" % (time.time() - start_time)) |