Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Note: Line separated json is now supported in <a href="http://pandas-docs.github.io/pandas-docs-travis/io.html#io-jsonl" rel="nofollow noreferrer"><code>read_json</code></a> (since 0.19.0):</p> <pre><code>In [31]: pd.read_json('{"a":1,"b":2}\n{"a":3,"b":4}', lines=True) Out[31]: a b 0 1 2 1 3 4 </code></pre> <p>or with a file/filepath rather than a json string:</p> <pre><code>pd.read_json(json_file) </code></pre> <hr> <p>It's going to depend on the size of you DataFrames which is faster, but another option is to use <code>str.join</code> to smash your multi line "JSON" (Note: it's not valid json), into valid json and use read_json:</p> <pre><code>In [11]: '[%s]' % ','.join(test.splitlines()) Out[11]: '[{"a":1,"b":2},{"a":3,"b":4}]' </code></pre> <p>For this tiny example this is slower, if around 100 it's the similar, signicant gains if it's larger...</p> <pre><code>In [21]: %timeit pd.read_json('[%s]' % ','.join(test.splitlines())) 1000 loops, best of 3: 977 µs per loop In [22]: %timeit l=[ json.loads(l) for l in test.splitlines()]; df = pd.DataFrame(l) 1000 loops, best of 3: 282 µs per loop In [23]: test_100 = '\n'.join([test] * 100) In [24]: %timeit pd.read_json('[%s]' % ','.join(test_100.splitlines())) 1000 loops, best of 3: 1.25 ms per loop In [25]: %timeit l = [json.loads(l) for l in test_100.splitlines()]; df = pd.DataFrame(l) 1000 loops, best of 3: 1.25 ms per loop In [26]: test_1000 = '\n'.join([test] * 1000) In [27]: %timeit l = [json.loads(l) for l in test_1000.splitlines()]; df = pd.DataFrame(l) 100 loops, best of 3: 9.78 ms per loop In [28]: %timeit pd.read_json('[%s]' % ','.join(test_1000.splitlines())) 100 loops, best of 3: 3.36 ms per loop </code></pre> <p><em>Note: of that time the join is surprisingly fast.</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload