What pandas function does change the column type in an "inline" manner?
<p>I know that the following commands could help change the column type:</p>

<pre><code>df['date'] = str(df['date']) 

df['A'] = pd.to_datetime(df['A'])

df['A'] = df.A.astype(np.datetime64)
</code></pre>

<p>But do you know a better way to change the column type in an inline manner to make it in one line following with other aggregating commands such as groupby, dropna, etc. For example:</p>

<pre><code>df\
#.function to cast df.A to np.datetime64 \ 
.groupby('C') \
.apply(lambda x: x.set_index('A').resample('1M').sum())
</code></pre>

<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.assign.html" rel="nofollow">assign</a>:</p>

<pre><code>df.assign(A=pd.to_datetime(df['A']))
</code></pre>

<hr>

<pre><code>df = pd.DataFrame({'A': ['20150101', '20140702'], 'B': [1, 2]})
df
Out: 
          A  B
0  20150101  1
1  20140702  2

df.assign(A=pd.to_datetime(df['A']))
Out: 
           A  B
0 2015-01-01  1
1 2014-07-02  2
</code></pre>

python pandas