title: How to reassign a Pandas dataframe value using the .apply() method?
body: <p>Is there a way to reassign values in a pandas dataframe using the .apply() method?</p>
  <p>I have this code:</p>
  <pre><code>import pandas as pd
  df = pd.DataFrame({'switch': ['ON', 'OFF', 'ON'], 
                     'value': [10, 15, 20]})
  print (df, '\n')
  
  
  def myfunc(row):
      if row['switch']  == 'ON':
          row['value'] = 500
      elif row['switch']  == 'OFF':
          row['value'] = 0
  
  df = df.apply(myfunc, axis=1)
  print (df)
  </code></pre>
  <p>The code is not working. I am trying to achieve the following output after running the .apply() method:</p>
  <pre><code>  switch  value
  0     ON     500
  1    OFF     0
  2     ON     500 
  </code></pre>
  <p>Why is the &quot;row['value'] = 500&quot; assignment not working and how can I rewrite it to make it work?</p>