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?
#11
Thank you for your help! You are right, it is USDA nutrition database. However, I already extracted all the needed data observations though the use of pandas dataframe. Again, thank you for the help.
Reply
#12
Please, if you would, share your solution with other users
Reply
#13
(Feb-06-2018, 07:02 PM)Larz60+ Wrote: Please, if you would, share your solution with other users

I have added this code to the one that we have discussed:

group=[]
food_name=[]
manufacturer=[]
nutrients=[]
for index, row in data_df.iterrows():
    group1 = row['group']
    group.append(group1)
    group_df = pd.DataFrame({'group': group})
    food_name1 = row['name']['long']
    food_name.append(food_name1)    
    food_name_df = pd.DataFrame({'food_name': food_name})
    manufacturer1 = row['manufacturer']
    manufacturer.append(manufacturer1)    
    manufacturer_df = pd.DataFrame({'manufacturer': manufacturer})    
    nutrients1 = row['nutrients']
    nutrients.append(nutrients1)    
    nutrients_df = pd.DataFrame({'nutrients': nutrients})

nutrient_name = nutrients_df['nutrients'].apply(pd.Series)[0].apply(pd.Series)
nutrient_name1 = nutrient_name['name']
nutrient_name1_df = pd.DataFrame({'nutrient_name1': nutrient_name1})
nutrient_value = nutrient_name['value']
nutrient_value_df = pd.DataFrame({'nutrient_value': nutrient_value})


merged_food_name = nutrient_name1_df.join(food_name_df).join(nutrient_value_df)

AminoAcids = ['Alanine', 'Arginine', 'Asparagine', 'Aspartic acid', 'Cysteine', 'Glutamic acid', 'Glutamine', 'Glycine','Histidine','Isoleucine','Leucine','Lysine','Methionine','Phenylalanine','Proline','Serine','Threonine','Tryptophan','Tyrosine','Valine']

for acid in AminoAcids:
    select_indices = list(np.where(merged_food_name["nutrient_name1"] == i)[0])
    print(merged_food_name.iloc[select_indices])

select_indices = list(np.where(merged_food_name["nutrient_name1"] == 'Asparagine')[0])
print(merged_food_name.iloc[select_indices])
Reply
#14
Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  extract specific content in a pandas dataframe with a regex? steve1040 0 10,497 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