I have a python function defined:
def func_1(df):
df_1 = df.drop_duplicates('Heir_1')
value = df['Amount_1'].sum()
return df_1
This is a value basic and simplified representation of my function. I just need to return two values from a function, one dataframe and other a variable. Is there a way i can do it?
I tried using a variable inside a function which i can use outside: the function: func_1.newone = df_1['Heir_2'].tolist()
I can access this outside the function but this variable does not update at each instance the function is called so it gives the same value again and again.
I also tried to save it in the dataframe like below but this gives me an error.
df_1['var1'] = df_1['Heir_2'].tolist()
Error:
ValueError: Length of values does not match length of index
Is there a solution to this? My main aim is just to reuse the value of a variable outside a function either by putting it into a return dataframe
which i can access at the end of each iteration.