Created
June 24, 2018 21:17
-
-
Save eliask/1d4e2fa58a1f077357e5a4187aabb6a6 to your computer and use it in GitHub Desktop.
Convert arff to json with Python and liac-arff
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
#!/bin/sh | |
# Usage: arff2json.sh < foo.arff > foo.json | |
# Requires arff: pip install liac-arff | |
# Why shell instead of python? Probably because I thought the default one-liner was neat:) | |
# Default format: .data = list of lists | |
python -c 'import json,sys,arff;json.dump(arff.load(sys.stdin),sys.stdout)' | |
exit 0 | |
# Or convert data to attribute maps: .data = list of JSON objects/dicts | |
python -c 'import json,sys,arff | |
data = arff.load(sys.stdin) | |
header = [x[0] for x in data["attributes"]] | |
data["data"] = [dict(zip(header,v)) for v in data["data"]] | |
json.dump(data, sys.stdout)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment