I have the following main DataFrame:
food_df.
Fruit |
---|
Apple |
Tomato |
Cranberry |
Orange |
Papaya |
Peach |
Pear |
Avocado |
Kiwi |
And previusly I defined some auxiliar DataFrames such as Red_df, Orange_df and Green_df.
I need to create a function that return me the correct auxiliar DataFrame according to the "Food" name input.
For instance, if the Food name is "Apple" OR "Tomato" OR "Cranberry" then I need to get back the Red_df. If the Food name is "Orange" OR "Papaya" OR "Peach", then I need to get back the Orange_df. If the Food name is "Pear" OR "Avocado" OR "Kiwi", then I need to get back the Green_df, and so on.
The following is the code that I've written:
import pandas as pd
data={'Fruit':['Apple', 'Tomato' ,'Cranberry', 'Orange', 'Papaya', 'Peach', 'Pear', 'Avocado', 'Kiwi']}
food_df=pd.DataFrame(data)
data2={'Color':['Red']}
Red_df=pd.DataFrame(data2)
data3={'Color':['Orange']}
Orange_df=pd.DataFrame(data3)
data4={'Color':['Green']}
Green_df=pd.DataFrame(data4)
del data, data2, data3, data4
def function(food):
print(Color),
if[(food_df["Fruit"]=='Apple') | (food_df["Fruit"]=='Tomato') | (food_df["Fruit"]=='Cranberry')]:
Color=Red_df
if[(food_df["Fruit"]=='Orange') | (food_df["Fruit"]=='Papaya') | (food_df["Fruit"]=='Peach')]:
Color=Orange_df
if[(food_df["Fruit"]=='Pear') | (food_df["Fruit"]=='Avocado') | (food_df["Fruit"]=='Kiwi')]:
Color=Green_df
for y in range(0,len(food_df["Fruit"])):
food=food_df.loc[y, 'Fruit']
function(food)
How can I fix the function to get it working?
I can't figure what the problem is.