Feb-05-2018, 03:57 PM
Dear Python Users,
I have a json database "data_df" [8194 rows x 6 columns]. The sample of the data is uploaded below.
I have the following code:
nutrient value Food
Alanine 8 Gelatins, dry powder
Please, advise me this issue
I have a json database "data_df" [8194 rows x 6 columns]. The sample of the data is uploaded below.
nutrients \ 0 [{'code': '203cp1252', 'name': 'Proteincp1252'... 1 [{'code': '203cp1252', 'name': 'Proteincp1252'... 2 [{'code': '203cp1252', 'name': 'Proteincp1252'... 3 [{'code': '203cp1252', 'name': 'Proteincp1252'. ... name \ 0 {'long': 'Butter, saltedcp1252', 'common': ['c... 1 {'long': 'Butter, whipped, with saltcp1252', '... 2 {'long': 'Butter oil, anhydrouscp1252', 'commo... ...What I want is to output a table that will show different parts of the group (Alanine, Glycine, Histidine etc) and the foods in which they are present (Gelatins, dry powder, beluga, meat..etc).
I have the following code:
AminoAcid = ['Alaninecp1252', 'Argininecp1252', 'Aspartic acidcp1252', 'Cystinecp1252', 'Glutamic acidcp1252', 'Glycinecp1252', 'Histidinecp1252', 'Hydroxyprolinecp1252', 'Isoleucinecp1252', 'Leucinecp1252', 'Lysinecp1252', 'Methioninecp1252', 'Phenylalaninecp1252', 'Prolinecp1252', 'Serinecp1252', 'Threoninecp1252', 'Tryptophancp1252', 'Tyrosinecp1252', 'Valinecp1252'] for index, row in data_df.iterrows(): group = row['group'] food = row['name']['long'] manufacturer = row['manufacturer'] nutrients = row['nutrients'] for nutrient in nutrients: nutrient_name = nutrient['name'] if any(e == nutrient_name for e in AminoAcid): nutrient_val = nutrient['value'] nutrient_unit = nutrient['units']However, I dont know how to continue.. what I want is smth like this:
nutrient value Food
Alanine 8 Gelatins, dry powder
Please, advise me this issue