i received single JSON's (500 JSON's) and modified it by adding them to the end of an existing list with the append() method.
d_path = r'--PATH HERE--'
d_files = [f for f in listdir(d_path) if isfile(join(d_path,f))]
n = num_data
d_dicts=[]
for counter,d_file in enumerate(d_files):
with open(d_path+'\\'+d_file,encoding="utf8") as json_data:
d_dicts.append(json.load(json_data))
if counter == num_data:
break
After this step i tried using json_normalize to normalize the JSON data into a flat table (Pandas DataFrame with a total of 500 rows).
df = json_normalize(d)
Additional Info:
class 'pandas.core.frame.DataFrame'
dtypes: float64(8), int64(3), object(9)
So far it worked out nicely except for one column. I ended up having one column with a List of dictionaries in each row. I tried to look for a solution but I can't find one that helps me. Each row has a Nested dictionary.
Here is an example of three rows of the column named Info_column with fictional data but the same structure:
Info_column
[{**'Greeting':** 'Good day', 'Group': '1.2', 'Window': None,
'Value1': 17.0, 'Value2': 13.23, 'Value3': 11.0,
'Date1': '2013-09-04', 'Date2': '2012-09-05', 'Date3': '2015-07-22',
'Married': False, 'Country': None,
'Person': [{'Age': '25', 'Number': '82', 'Value4': 19.2,
'Column1': None, 'Column2': None, 'Column3': None, 'Column4': None}]}]
[{'Greeting': 'Good afternoon', 'Group': '1.4', 'Window': None,
'Value1': 12.0, 'Value2': 9.23, 'Value3': 2.0,
'Date1': '2016-09-04', 'Date2': '2016-09-16', 'Date3': '2016-07-05',
'Married': True, 'Country': Germany,
'Person': [{'Age': '30', 'Number': '9', 'Value4': 10.0,
'Column1': None, 'Column2': None, 'Column3': None, 'Column4': None}]}]
[{'Greeting': 'Good evening', 'Group': '3.0', 'Window': True,
'Value1': 24.0, 'Value2': 15.5, 'Value3': 2.0,
'Date1': '2019-02-01', 'Date2': '2019-05-05', 'Date3': '2018-05-03',
'Married': False, 'Country': Spain,
'Person': [{'Age': '24', 'Number': '12', 'Value4': 8.2,
'Column1': None, 'Column2': None, 'Column3': None, 'Column4': None}]}]
What is the correct way?
My goal is to have the Information for every row in this column as additional columns in my dataframe.
Columns that I need as additional columns next to the other columns in my DataFrame df:
Greeting, Group, Window, Value1, Value2, Value3, Date1, Date2, Date3, Married, Country, Person_Age, Person_Number, Person_Value4, Person_Column1, Person_Column2, Person_Column3, Person_Column4
Thanks a lot for your help
Regards, Elle