(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])