Skip to content Skip to sidebar Skip to footer

Conversion Between Json And Dataframe Using Python

I have the following code: responsedata = requests.get(url, data=data, headers=hed, verify=False) sample_object = pd.DataFrame(responsedata.json())['results'].to_dict() func(sample

Solution 1:

From what I can tell pd.DataFrame(responsedata.json())['results'].to_dict()

gives you {0: (first data set), 1: (second data set)},

while responsedata.json()['results']

gives you a list of [(first data set), (second data set)].

In order to turn the list into a dictionary like the first, use

sample_object = {i: data for i, data in enumerate(responsedata2)}

enumerate is a generator that takes an iterable such as ['a', 'b', 'c', ...] and returns tuples (0, 'a'), (1, 'b'), etc.

Post a Comment for "Conversion Between Json And Dataframe Using Python"