this is my dataframe:
df = pd.DataFrame({'sym': ['msft', 'amd', 'bac', 'tsla'], 'close': [100, 30, 70, 80], 'sector': ['tech', 'tech', 'bank', 'auto'], 'watch_list': [1, 2, 2, 1]})
and this is the simpilified form of function that I want to use:
def add_volume(df):
df['volume'] = [1000, 2000, 3000, 4000]
return df
I want to pass two optional arguments(sector, watch_list) to my function that select the rows that I want for example if I call the function like this
add_volume (df, sector=['tech'], watch_list=[1])
It returns the first row.
And if I just call it like this
add_volume(df, watch_list = [1])
it returns the first and last row. I want both of the arguments to be optional.
def add_volume(df, sector=None, watch_list=None):Inside function check if arguments are notNoneand use them or not.