Python Forum
How to extract specific information from json database?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to extract specific information from json database?
#1
Dear Python Users,

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
Reply


Messages In This Thread
How to extract specific information from json database? - by Alberto - Feb-05-2018, 03:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Training a model to identify specific SMS types and extract relevant data? lord_of_cinder 0 999 Oct-10-2022, 04:35 AM
Last Post: lord_of_cinder
  extract specific content in a pandas dataframe with a regex? steve1040 0 13,576 Oct-05-2017, 03:17 AM
Last Post: steve1040

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020