1
I have the following Dataframe:
import pandas as pd
df = pd.DataFrame({'id_emp': [1,2,3,4,1],
'name_emp': ['x','y','z','w','x'],
'donnated_value':[1100,11000,500,300,1000],
'refound_value':[22000,22000,50000,450,90]
})
df['return_percentagem'] = 100 * df['refound_value']/df['donnated_value']
df['classification_roi'] = ''
I want to assign values to df['classification_roi'] from the values of df['return_percentage']. Example: df values["return_percentage'] > 100, df['classification_roi'] = 'Good investment';df values["return_percentage'] between 99 and 50, df['classification_roi'] = 'Medium investment';df values["return_percentage'] <50 , df['classification_roi'] = 'Bad investment'.
I’m trying the following, but all lines receive as value 'Bad Investment', IE, all are entering the first loop
def comunidade():
for i in df['return_percentagem'].values:
if i < 50:
df['classification_roi'] = 'Bad Investment'
elif i >=50 and i < 100:
df['classification_roi'] = 'Median Investment'
elif i >= 100:
df['classification_roi'] = 'Good Investment'
comunidade()
I appreciate any help
Thank you, solved the problem.
– Costa.Gustavo