Json_normalize help, not able to normalize in loop

Hello All,

At a fix right now, when I use a cell in excel as an input to json_normalize, it works perfectly.

When I use iteration for each cell, json_normalize gives error.

I even tried creating a dict of all cells, still the json_normalize does not work over it.

Can someone please help me in this.

Thanks already.

At a fix right now, when I use a cell in excel as an input to
json_normalize, it works perfectly.

Is json_normalize this? json-normalize · PyPI

When I use iteration for each cell, json_normalize gives error.
I even tried creating a dict of all cells, still the json_normalize
does not work over it.

We would need to see your code. Please provide it in a reply between
triple backticks, eg:

 ```
 your code
 goes here
 ```

There’s a </> button in the compose tool bar which makes such a
section.

We also need to see the entire error and so forth.

Cheers,
Cameron Simpson cs@cskk.id.au

Hey Cameron,

Thanks alot for the reply!

There is a long json string and I have changed it to an excel file using pandas and there is a comments column in that json which itself is a json file, I need to explode each row of that comments column

The below code works correctly as its working on a single json comments field .

import json
import pandas as pd
data1="Some large json file comments field"
df = pd.json_normalize(data1)
print(df.head())
df.to_excel(r"C:\Users\Niraj.Chaughule\Desktop\testexport1.xlsx", index=False)

But when i try to iterate it, it gives an error–

import json
import pandas as pd
import openpyxl

wb = openpyxl.load_workbook(r'C:\Users\Niraj.Chaughule\Desktop\scannedcol.xlsx')
sheet = wb.active

cell_range_values = []
for row in sheet.iter_rows(min_row=1, max_row=3, min_col=1, max_col=3):
    cell_values = [cell.value for cell in row]
    cell_range_values.append(cell_values)
print("Cell range A1 to C3:")
for row_values in cell_range_values:
    x=print(row_values)
    print (x)
    normalized_data = pd.json_normalize(x)
    print(normalized_data)

This above code always gives an error either unicode escape or raise not implemented error.

I have tried using json_loads, json_dumps and then passing it to json_normalize, still it results in an error.

The error is—
line 447, in json_normalize
raise NotImplementedError
NotImplementedError

or sometimes it gives unicode escape error \uxxxx or \Uxxxx.

Do let me know if anything else is requried.

The line x=print(row_values) looks wrong. print returns None, so that line prints the value of row_values and then sets x to None.

The Unicode error might be the result of trying to print something that has a character that the output’s encoding can’t handle.

Hi Matthew, Thanks a lot for the reply :slightly_smiling_face:

Can you suggest any better way for the iteration here which may work correctly?.

Like an example with some code?.