Why use pandas.assign rather than simply initialize new column? : <p>I just discovered the <code>assign</code> method for pandas dataframes, and it looks nice and very similar to dplyr's <code>mutate</code> in R. However, I've always gotten by by just initializing a new column 'on the fly'. Is there a reason why <code>assign</code> is better?</p>

<p>For instance (based on the example in the pandas documentation), to create a new column in a dataframe, I could just do this:</p>

<pre><code>df = DataFrame({'A': range(1, 11), 'B': np.random.randn(10)})
df['ln_A'] = np.log(df['A'])
</code></pre>

<p>but the <code>pandas.DataFrame.assign</code> documentation recommends doing this:</p>

<pre><code>df.assign(ln_A = lambda x: np.log(x.A))
# or 
newcol = np.log(df['A'])
df.assign(ln_A=newcol)
</code></pre>

<p>Both methods return the same dataframe. In fact, the first method (my 'on the fly' method) is significantly faster (0.20225788200332318 seconds for 1000 iterations) than the <code>.assign</code> method (0.3526602769998135 seconds for 1000 iterations). </p>

<p>So is there a reason I should stop using my old method in favour of <code>df.assign</code>? </p>
