Q:

Apply a function to modify multiple columns with if else logic

I am trying to write a function with if-else logic which will modify two columns in my data frame. But its not working. Following is my function
def get_comment_status(df):
    if df['address'] == 'NY':
        df['comment'] = 'call tomorrow'
        df['selection_status'] = 'interview scheduled'
        return df['comment'] 
        return df['selection_status']
    else:
        df['comment'] = 'Dont call'
        df['selection_status'] = 'application rejected'
        return df['comment']
        return df['selection_status']

and then execute the function as :
df[['comment', 'selection_status']] = df.apply(get_comment_status, axis = 1)

But I am getting error. What am I doing wrong ? My guess is probably the df.apply() syntax is wrong
Error Message: 

TypeError: 'str' object cannot be interpreted as an integer 
  KeyError:('address', 'occurred at index 0')

sample dataframe:
df = pd.DataFrame({'address': ['NY', 'CA', 'NJ', 'NY', 'WS', 'OR', 'OR'],
               'name1': ['john', 'mayer', 'dylan', 'bob', 'mary', 'jake', 'rob'],
               'name2': ['mayer', 'dylan', 'mayer', 'bob', 'bob', 'tim', 'ben'],
               'comment': ['n/a', 'n/a', 'n/a', 'n/a', 'n/a', 'n/a', 'n/a'],
               'score': [90, 8, 88, 72, 34, 95, 50],
               'selection_status': ['inprogress', 'inprogress', 'inprogress', 'inprogress', 'inprogress', 'inprogress', 'inprogress']})

I have also thought of using lambda function but it doesnt work as I was trying to assign value to 'comment' and 'selection_status' column using '='
Note: I have checked this question which is similar by title but doesn't solve my problem.

A:

What you try to do is not very consistent with Pandas philosophy. Also, apply is a very inefficient function. You probably should use Numpy where:
import numpy as np
df['comment'] = np.where(df['address'] == 'NY',
                  'call tomorrow', 'Dont call')
df['selection_status'] = np.where(df['address'] == 'NY',
                           'interview scheduled', 'application rejected')

Or boolean indexing:
df.loc[df['address'] == 'NY', ['comment', 'selection_status']] \
         = 'call tomorrow', 'interview scheduled'
df.loc[df['address'] != 'NY', ['comment', 'selection_status']] \
         = 'Dont call', 'application rejected'

