I am currently trying to retrieve values from cells in a Dataframe. I am searching through a dataframe to find strings that match values in a column in a row, then returning a value in that row from another column.
My code looks like this:
df:
Fruit   Value
apple     7.0
banana    6.0
orange    8.0
lemon     3.0
melon     2.0
myList = ['apple', 'lemon']
result = []
for word in myList:
    result.append(df['Value'].loc[df['Fruit'] == word].values)
print(result)
The print statement is outputting:
[array([], dtype=float64), array([7.0]), array([], dtype=float64), array([3.0])]
My desired output is simply an array of float values:
[7.0, 3.0]
How would I go about cleaning my output to achieve this? My end goal is to get the average value of the array.
 
     
    