'How to convert dataframe rows into json

I have the following JSON structure: enter image description here

I'm trying to apply some functions but it tells me that:

AttributeError: 'NoneType' object has no attribute 'iterrows'.

So, I decided to convert it into JSON for each data frame row.

I tried the following code:

for i in data.index:
    data = data.loc[i].to_json("row{}.json".format(i))

But it gives me an error:

AttributeError: 'NoneType' object has no attribute 'index'

Any thoughts, please?



Solution 1:[1]

It sounds like your data is NoneType (Empty).

Usually, iterrows will be sufficient here.

for index, row in df.iterrows():
    print(index)

The issue could be in read_json() check your data with df.head()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nanthakumar J J