Basically I have a dataframe:
# initialize list of lists
data = [['tom', 10], ['nick', 15], ['juli', 14]]
# Create the pandas DataFrame
df = pd.DataFrame(data, columns=['Name', 'Amount'])
and I want to write a function that will apply a percentage change to certain rows based on the values I give it:
def function(x, pct):
if df['Name'] == x:
df['Amount'] = df['Amount'] - (df['Amount'] * pct), df['Amount']
else:
df['Amount'] = df['Amount']
return df
I know that I need to reference the data frame somewhere in the function but I'm struggling to figure out how to do it.