Please read Getting good answers to your questions. I would suggest paying particular attention to the section ‘Help others reproduce the problem’, in the link to How do I ask a good question? at the bottom there.
Your code and issue is not reproducible as provided.
Here is a minimal, toy example adapted from the incomplete code you provided:
import pandas as pd
mutual_funds = pd.DataFrame({'A': range(1, 6),
'B': range(10, 0, -2),
'Investment_Return': range(100, 0, -20),
'C C': range(10, 5, -1)})
good_return_threshold = 51
def classify_return(Investment_Return):
if Investment_Return> good_return_threshold:
return 'Good'
else:
return 'Not good'
mutual_funds['Return_Classification']= mutual_funds['Investment_Return'].apply(classify_return)
(Notice the code is formatted to be pasteable.).
This code works fine, as can be observed by clicking here and running it when the session starts. (Or click here if you want it in JupyterLite, which is a nice option when MyBinder-served sessions are being slow to come up.) (Here is the boring static view, but the two links prior are much more useful and I suggest using those primarily.)
In other words, I don’t see your reported issue with the limited code and information provided.
If however, I change the equivalent line you had an issue with to mutual_funds['Return_Classification']= mutual_funds['Z'].apply(classify_return)
, then I get KeyError: 'Z'
because there is no column named Z
in my dataframe.