Created
March 10, 2019 15:09
-
-
Save htahir1/37480d4902d8c2f0032146016fa8a9bc to your computer and use it in GitHub Desktop.
Comparison of loading JSON into pandas dataframe
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 pandas as pd | |
from time import time | |
from pprint import pprint | |
import simplejson | |
import json | |
import ujson | |
def _loads(data, serializer): | |
t_start = time() | |
serialized_data = serializer.loads(data) | |
t_serialization = time() - t_start | |
df = pd.DataFrame.from_dict(serialized_data) | |
t_end = time() - t_start | |
return { | |
"duration": t_end, | |
"columns": df.columns, | |
"shape": df.shape, | |
"serialization": t_serialization | |
} | |
with open("big.json", "r") as infile: | |
data = infile.read() | |
for method in [simplejson, json, ujson]: | |
result = _loads(data, method) | |
print "method: " + method.__name__ | |
print "total: " + str(result["duration"]) | |
print "serialization: " + str(result["serialization"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment