Dataframe from JSON formatted as text?
up vote
0
down vote
favorite
Is it possible to create a dataframe from JSON formatted as text, not as Python object?
With Python object, I could for example do:
from pandas.io.json import json_normalize
import requests
response = requests.get(url, params).json()
df = json_normalize(response)
but I want to achieve the same with response = requests.get(url,params).text
(flattening is not required though).
python json pandas dataframe
add a comment |
up vote
0
down vote
favorite
Is it possible to create a dataframe from JSON formatted as text, not as Python object?
With Python object, I could for example do:
from pandas.io.json import json_normalize
import requests
response = requests.get(url, params).json()
df = json_normalize(response)
but I want to achieve the same with response = requests.get(url,params).text
(flattening is not required though).
python json pandas dataframe
Can you put few lines of the data?
– pygo
Nov 9 at 17:21
@pygo why the list comprehension?
– roganjosh
Nov 9 at 17:24
@pygo I won't be reading JSON from file, I want to putrequests.get(url,params).text
response into a dataframe.
– barciewicz
Nov 9 at 17:26
@barciewicz, yes got it thats y i said i misread tehe question sorry :-)
– pygo
Nov 9 at 17:28
Is the.text
guaranteed to be valid JSON string?
– Idlehands
Nov 9 at 18:37
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Is it possible to create a dataframe from JSON formatted as text, not as Python object?
With Python object, I could for example do:
from pandas.io.json import json_normalize
import requests
response = requests.get(url, params).json()
df = json_normalize(response)
but I want to achieve the same with response = requests.get(url,params).text
(flattening is not required though).
python json pandas dataframe
Is it possible to create a dataframe from JSON formatted as text, not as Python object?
With Python object, I could for example do:
from pandas.io.json import json_normalize
import requests
response = requests.get(url, params).json()
df = json_normalize(response)
but I want to achieve the same with response = requests.get(url,params).text
(flattening is not required though).
python json pandas dataframe
python json pandas dataframe
asked Nov 9 at 17:16
barciewicz
426310
426310
Can you put few lines of the data?
– pygo
Nov 9 at 17:21
@pygo why the list comprehension?
– roganjosh
Nov 9 at 17:24
@pygo I won't be reading JSON from file, I want to putrequests.get(url,params).text
response into a dataframe.
– barciewicz
Nov 9 at 17:26
@barciewicz, yes got it thats y i said i misread tehe question sorry :-)
– pygo
Nov 9 at 17:28
Is the.text
guaranteed to be valid JSON string?
– Idlehands
Nov 9 at 18:37
add a comment |
Can you put few lines of the data?
– pygo
Nov 9 at 17:21
@pygo why the list comprehension?
– roganjosh
Nov 9 at 17:24
@pygo I won't be reading JSON from file, I want to putrequests.get(url,params).text
response into a dataframe.
– barciewicz
Nov 9 at 17:26
@barciewicz, yes got it thats y i said i misread tehe question sorry :-)
– pygo
Nov 9 at 17:28
Is the.text
guaranteed to be valid JSON string?
– Idlehands
Nov 9 at 18:37
Can you put few lines of the data?
– pygo
Nov 9 at 17:21
Can you put few lines of the data?
– pygo
Nov 9 at 17:21
@pygo why the list comprehension?
– roganjosh
Nov 9 at 17:24
@pygo why the list comprehension?
– roganjosh
Nov 9 at 17:24
@pygo I won't be reading JSON from file, I want to put
requests.get(url,params).text
response into a dataframe.– barciewicz
Nov 9 at 17:26
@pygo I won't be reading JSON from file, I want to put
requests.get(url,params).text
response into a dataframe.– barciewicz
Nov 9 at 17:26
@barciewicz, yes got it thats y i said i misread tehe question sorry :-)
– pygo
Nov 9 at 17:28
@barciewicz, yes got it thats y i said i misread tehe question sorry :-)
– pygo
Nov 9 at 17:28
Is the
.text
guaranteed to be valid JSON string?– Idlehands
Nov 9 at 18:37
Is the
.text
guaranteed to be valid JSON string?– Idlehands
Nov 9 at 18:37
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
I usually create dataframe from json using "read_json"
import pandas as pd
import requests
data = requests.get(url, params).content
df = pd.read_json(data)
df.head()
Thanks, sadly this gives meValueError: arrays must all be same length
atread_json
line, I guess because my JSON is nested. Do you know how to work around it?
– barciewicz
Nov 9 at 18:01
replace read_json line by: from pandas.io.json import json_normalize, loads df = json_normalize(loads(data))
– lfkopp
Nov 10 at 1:09
add a comment |
up vote
0
down vote
If your response = requests.get(url,params).text
is guaranteed to give you a valid JSON string, then all you need to do is as follows:
from pandas.io.json import json_normalize, loads
import requests
response = requests.get(url, params).text
df = json_normalize(loads(response))
Here we make use of json
's loads
to convert the JSON string to a Python object before passing back to json_normalize
.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I usually create dataframe from json using "read_json"
import pandas as pd
import requests
data = requests.get(url, params).content
df = pd.read_json(data)
df.head()
Thanks, sadly this gives meValueError: arrays must all be same length
atread_json
line, I guess because my JSON is nested. Do you know how to work around it?
– barciewicz
Nov 9 at 18:01
replace read_json line by: from pandas.io.json import json_normalize, loads df = json_normalize(loads(data))
– lfkopp
Nov 10 at 1:09
add a comment |
up vote
0
down vote
I usually create dataframe from json using "read_json"
import pandas as pd
import requests
data = requests.get(url, params).content
df = pd.read_json(data)
df.head()
Thanks, sadly this gives meValueError: arrays must all be same length
atread_json
line, I guess because my JSON is nested. Do you know how to work around it?
– barciewicz
Nov 9 at 18:01
replace read_json line by: from pandas.io.json import json_normalize, loads df = json_normalize(loads(data))
– lfkopp
Nov 10 at 1:09
add a comment |
up vote
0
down vote
up vote
0
down vote
I usually create dataframe from json using "read_json"
import pandas as pd
import requests
data = requests.get(url, params).content
df = pd.read_json(data)
df.head()
I usually create dataframe from json using "read_json"
import pandas as pd
import requests
data = requests.get(url, params).content
df = pd.read_json(data)
df.head()
answered Nov 9 at 17:30
lfkopp
692
692
Thanks, sadly this gives meValueError: arrays must all be same length
atread_json
line, I guess because my JSON is nested. Do you know how to work around it?
– barciewicz
Nov 9 at 18:01
replace read_json line by: from pandas.io.json import json_normalize, loads df = json_normalize(loads(data))
– lfkopp
Nov 10 at 1:09
add a comment |
Thanks, sadly this gives meValueError: arrays must all be same length
atread_json
line, I guess because my JSON is nested. Do you know how to work around it?
– barciewicz
Nov 9 at 18:01
replace read_json line by: from pandas.io.json import json_normalize, loads df = json_normalize(loads(data))
– lfkopp
Nov 10 at 1:09
Thanks, sadly this gives me
ValueError: arrays must all be same length
at read_json
line, I guess because my JSON is nested. Do you know how to work around it?– barciewicz
Nov 9 at 18:01
Thanks, sadly this gives me
ValueError: arrays must all be same length
at read_json
line, I guess because my JSON is nested. Do you know how to work around it?– barciewicz
Nov 9 at 18:01
replace read_json line by: from pandas.io.json import json_normalize, loads df = json_normalize(loads(data))
– lfkopp
Nov 10 at 1:09
replace read_json line by: from pandas.io.json import json_normalize, loads df = json_normalize(loads(data))
– lfkopp
Nov 10 at 1:09
add a comment |
up vote
0
down vote
If your response = requests.get(url,params).text
is guaranteed to give you a valid JSON string, then all you need to do is as follows:
from pandas.io.json import json_normalize, loads
import requests
response = requests.get(url, params).text
df = json_normalize(loads(response))
Here we make use of json
's loads
to convert the JSON string to a Python object before passing back to json_normalize
.
add a comment |
up vote
0
down vote
If your response = requests.get(url,params).text
is guaranteed to give you a valid JSON string, then all you need to do is as follows:
from pandas.io.json import json_normalize, loads
import requests
response = requests.get(url, params).text
df = json_normalize(loads(response))
Here we make use of json
's loads
to convert the JSON string to a Python object before passing back to json_normalize
.
add a comment |
up vote
0
down vote
up vote
0
down vote
If your response = requests.get(url,params).text
is guaranteed to give you a valid JSON string, then all you need to do is as follows:
from pandas.io.json import json_normalize, loads
import requests
response = requests.get(url, params).text
df = json_normalize(loads(response))
Here we make use of json
's loads
to convert the JSON string to a Python object before passing back to json_normalize
.
If your response = requests.get(url,params).text
is guaranteed to give you a valid JSON string, then all you need to do is as follows:
from pandas.io.json import json_normalize, loads
import requests
response = requests.get(url, params).text
df = json_normalize(loads(response))
Here we make use of json
's loads
to convert the JSON string to a Python object before passing back to json_normalize
.
answered Nov 9 at 18:39
Idlehands
3,2901316
3,2901316
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230467%2fdataframe-from-json-formatted-as-text%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you put few lines of the data?
– pygo
Nov 9 at 17:21
@pygo why the list comprehension?
– roganjosh
Nov 9 at 17:24
@pygo I won't be reading JSON from file, I want to put
requests.get(url,params).text
response into a dataframe.– barciewicz
Nov 9 at 17:26
@barciewicz, yes got it thats y i said i misread tehe question sorry :-)
– pygo
Nov 9 at 17:28
Is the
.text
guaranteed to be valid JSON string?– Idlehands
Nov 9 at 18:37