ValueError: ('The truth value of a Series is ambiguous after applying if/else condition in Pandas data frames
(Assuming the error comes from the 2nd line)
This question on StackOverflow has a great answer to your problem
Essentially, change
 if ((vars_df['variable_name']) in list1) &amp; (vars_df['direction'] =='up'):

to this
if (((vars_df['variable_name']) in list1) &amp; (vars_df['direction'] =='up')).any():

or to this, if all of the values should be True
if (((vars_df['variable_name']) in list1) &amp; (vars_df['direction'] =='up')).all():

Hope this helps :)