title: how to use lambda inside a function
body: <p>I am trying to create a function to perform operations with columns of a data frame, but in the end it gives me an error because when defining the lambda x: x.variable, variable takes it literally, how do I assign the value it has? variable in the x.</p>
  <pre><code>import pandas as pd
  d = {'col1': [1, 2], 'col2': [3, 4]}
  df = pd.DataFrame(data=d)
  
  def example(dataFrame, variable):
    dataFrame= dataFrame.assign(newColumn= lambda x: x.variable**2)
  example(df,'col1')
  </code></pre>
  <p>AttributeError: 'DataFrame' object has no attribute 'variable'</p>
  <p>How can i fix this?</p>