<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import pandas as pd
import datetime as dt

# only one row
s = pd.DataFrame(columns=['a', 'b', 'c'], index=[1])
s.loc[:, 'a'] = dt.datetime.now()
s.loc[:, 'b'] = 1
s.loc[:, 'c'] = dt.datetime.now()

s.loc[:, 'b'] = s.loc[:, 'b'].apply(lambda x: x + 1)

# no problem
s.loc[:, 'c'] = s.loc[:, 'c'].apply(lambda x: x.date().strftime(&quot;%Y-%m-%d&quot;))

# raise TypeError 
s.loc[:, 'a'] = s.loc[:, 'a'].apply(lambda x: x.date().strftime(&quot;%Y-%m-%d&quot;))

# raise TypeError 
temp = s.loc[:, 'a'].apply(lambda x: x.date().strftime(&quot;%Y-%m-%d&quot;))
s.loc[:, 'a'] = temp



# no problems when DataFrame has more than 2 rows
s = pd.DataFrame(columns=['a', 'b', 'c'], index=[1, 2])
s.loc[:, 'a'] = dt.datetime.now()
s.loc[:, 'b'] = 1
s.loc[:, 'c'] = dt.datetime.now()

s.loc[:, 'b'] = s.loc[:, 'b'].apply(lambda x: x + 1)
temp = s.loc[:, 'a'].apply(lambda x: x.date().strftime(&quot;%Y-%m-%d&quot;))
s.loc[:, 'a'] = temp
# s.loc[:, 'a'] = s.loc[:, 'a'].apply(lambda x: x.date().strftime(&quot;%Y-%m-%d&quot;))
s.loc[:, 'c'] = s.loc[:, 'c'].apply(lambda x: x.date().strftime(&quot;%Y-%m-%d&quot;))
"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>
<span class="pl-k">import</span> <span class="pl-s1">datetime</span> <span class="pl-k">as</span> <span class="pl-s1">dt</span>

<span class="pl-c"># only one row</span>
<span class="pl-s1">s</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>(<span class="pl-s1">columns</span><span class="pl-c1">=</span>[<span class="pl-s">'a'</span>, <span class="pl-s">'b'</span>, <span class="pl-s">'c'</span>], <span class="pl-s1">index</span><span class="pl-c1">=</span>[<span class="pl-c1">1</span>])
<span class="pl-s1">s</span>.<span class="pl-s1">loc</span>[:, <span class="pl-s">'a'</span>] <span class="pl-c1">=</span> <span class="pl-s1">dt</span>.<span class="pl-s1">datetime</span>.<span class="pl-en">now</span>()
<span class="pl-s1">s</span>.<span class="pl-s1">loc</span>[:, <span class="pl-s">'b'</span>] <span class="pl-c1">=</span> <span class="pl-c1">1</span>
<span class="pl-s1">s</span>.<span class="pl-s1">loc</span>[:, <span class="pl-s">'c'</span>] <span class="pl-c1">=</span> <span class="pl-s1">dt</span>.<span class="pl-s1">datetime</span>.<span class="pl-en">now</span>()

<span class="pl-s1">s</span>.<span class="pl-s1">loc</span>[:, <span class="pl-s">'b'</span>] <span class="pl-c1">=</span> <span class="pl-s1">s</span>.<span class="pl-s1">loc</span>[:, <span class="pl-s">'b'</span>].<span class="pl-en">apply</span>(<span class="pl-k">lambda</span> <span class="pl-s1">x</span>: <span class="pl-s1">x</span> <span class="pl-c1">+</span> <span class="pl-c1">1</span>)

<span class="pl-c"># no problem</span>
<span class="pl-s1">s</span>.<span class="pl-s1">loc</span>[:, <span class="pl-s">'c'</span>] <span class="pl-c1">=</span> <span class="pl-s1">s</span>.<span class="pl-s1">loc</span>[:, <span class="pl-s">'c'</span>].<span class="pl-en">apply</span>(<span class="pl-k">lambda</span> <span class="pl-s1">x</span>: <span class="pl-s1">x</span>.<span class="pl-en">date</span>().<span class="pl-en">strftime</span>(<span class="pl-s">"%Y-%m-%d"</span>))

<span class="pl-c"># raise TypeError </span>
<span class="pl-s1">s</span>.<span class="pl-s1">loc</span>[:, <span class="pl-s">'a'</span>] <span class="pl-c1">=</span> <span class="pl-s1">s</span>.<span class="pl-s1">loc</span>[:, <span class="pl-s">'a'</span>].<span class="pl-en">apply</span>(<span class="pl-k">lambda</span> <span class="pl-s1">x</span>: <span class="pl-s1">x</span>.<span class="pl-en">date</span>().<span class="pl-en">strftime</span>(<span class="pl-s">"%Y-%m-%d"</span>))

<span class="pl-c"># raise TypeError </span>
<span class="pl-s1">temp</span> <span class="pl-c1">=</span> <span class="pl-s1">s</span>.<span class="pl-s1">loc</span>[:, <span class="pl-s">'a'</span>].<span class="pl-en">apply</span>(<span class="pl-k">lambda</span> <span class="pl-s1">x</span>: <span class="pl-s1">x</span>.<span class="pl-en">date</span>().<span class="pl-en">strftime</span>(<span class="pl-s">"%Y-%m-%d"</span>))
<span class="pl-s1">s</span>.<span class="pl-s1">loc</span>[:, <span class="pl-s">'a'</span>] <span class="pl-c1">=</span> <span class="pl-s1">temp</span>



<span class="pl-c"># no problems when DataFrame has more than 2 rows</span>
<span class="pl-s1">s</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>(<span class="pl-s1">columns</span><span class="pl-c1">=</span>[<span class="pl-s">'a'</span>, <span class="pl-s">'b'</span>, <span class="pl-s">'c'</span>], <span class="pl-s1">index</span><span class="pl-c1">=</span>[<span class="pl-c1">1</span>, <span class="pl-c1">2</span>])
<span class="pl-s1">s</span>.<span class="pl-s1">loc</span>[:, <span class="pl-s">'a'</span>] <span class="pl-c1">=</span> <span class="pl-s1">dt</span>.<span class="pl-s1">datetime</span>.<span class="pl-en">now</span>()
<span class="pl-s1">s</span>.<span class="pl-s1">loc</span>[:, <span class="pl-s">'b'</span>] <span class="pl-c1">=</span> <span class="pl-c1">1</span>
<span class="pl-s1">s</span>.<span class="pl-s1">loc</span>[:, <span class="pl-s">'c'</span>] <span class="pl-c1">=</span> <span class="pl-s1">dt</span>.<span class="pl-s1">datetime</span>.<span class="pl-en">now</span>()

<span class="pl-s1">s</span>.<span class="pl-s1">loc</span>[:, <span class="pl-s">'b'</span>] <span class="pl-c1">=</span> <span class="pl-s1">s</span>.<span class="pl-s1">loc</span>[:, <span class="pl-s">'b'</span>].<span class="pl-en">apply</span>(<span class="pl-k">lambda</span> <span class="pl-s1">x</span>: <span class="pl-s1">x</span> <span class="pl-c1">+</span> <span class="pl-c1">1</span>)
<span class="pl-s1">temp</span> <span class="pl-c1">=</span> <span class="pl-s1">s</span>.<span class="pl-s1">loc</span>[:, <span class="pl-s">'a'</span>].<span class="pl-en">apply</span>(<span class="pl-k">lambda</span> <span class="pl-s1">x</span>: <span class="pl-s1">x</span>.<span class="pl-en">date</span>().<span class="pl-en">strftime</span>(<span class="pl-s">"%Y-%m-%d"</span>))
<span class="pl-s1">s</span>.<span class="pl-s1">loc</span>[:, <span class="pl-s">'a'</span>] <span class="pl-c1">=</span> <span class="pl-s1">temp</span>
<span class="pl-c"># s.loc[:, 'a'] = s.loc[:, 'a'].apply(lambda x: x.date().strftime("%Y-%m-%d"))</span>
<span class="pl-s1">s</span>.<span class="pl-s1">loc</span>[:, <span class="pl-s">'c'</span>] <span class="pl-c1">=</span> <span class="pl-s1">s</span>.<span class="pl-s1">loc</span>[:, <span class="pl-s">'c'</span>].<span class="pl-en">apply</span>(<span class="pl-k">lambda</span> <span class="pl-s1">x</span>: <span class="pl-s1">x</span>.<span class="pl-en">date</span>().<span class="pl-en">strftime</span>(<span class="pl-s">"%Y-%m-%d"</span>))</pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">In my situation, I need to get user's  login history from the database, then trans the type of the login time(timestamp in MySQL db, datetime64 in pandas) to string("%Y-%m-%d").  But when a user only has one login record, I have this problem occurred.<br>
Really got confused</p>
<h4 dir="auto">Expected Output</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
In[3]: s
Out[3]: 
            a  b           c
1  2017-10-30  2  2017-10-30

"><pre class="notranslate"><span class="pl-v">In</span>[<span class="pl-c1">3</span>]: <span class="pl-s1">s</span>
<span class="pl-v">Out</span>[<span class="pl-c1">3</span>]: 
            <span class="pl-s1">a</span>  <span class="pl-s1">b</span>           <span class="pl-s1">c</span>
<span class="pl-c1">1</span>  <span class="pl-c1">2017</span><span class="pl-c1">-</span><span class="pl-c1">10</span><span class="pl-c1">-</span><span class="pl-c1">30</span>  <span class="pl-c1">2</span>  <span class="pl-c1">2017</span><span class="pl-c1">-</span><span class="pl-c1">10</span><span class="pl-c1">-</span><span class="pl-c1">30</span>
</pre></div>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
<h2 dir="auto">INSTALLED VERSIONS</h2>
<p dir="auto">commit: None<br>
python: 3.5.3.final.0<br>
python-bits: 64<br>
OS: Windows<br>
OS-release: 10<br>
machine: AMD64<br>
processor: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: None<br>
LOCALE: None.None<br>
pandas: 0.19.2<br>
nose: None<br>
pip: 9.0.1<br>
setuptools: 36.2.7<br>
Cython: None<br>
numpy: 1.12.1<br>
scipy: 0.19.0<br>
statsmodels: None<br>
xarray: None<br>
IPython: 5.3.0<br>
sphinx: None<br>
patsy: None<br>
dateutil: 2.6.0<br>
pytz: 2016.10<br>
blosc: None<br>
bottleneck: None<br>
tables: None<br>
numexpr: None<br>
matplotlib: 2.0.2<br>
openpyxl: 2.4.8<br>
xlrd: 1.0.0<br>
xlwt: None<br>
xlsxwriter: None<br>
lxml: 3.7.3<br>
bs4: 4.6.0<br>
html5lib: 0.9999999<br>
httplib2: None<br>
apiclient: None<br>
sqlalchemy: 1.1.6<br>
pymysql: 0.7.10.None<br>
psycopg2: None<br>
jinja2: 2.9.5<br>
boto: None<br>
pandas_datareader: 0.4.0</p>
</details>
<p dir="auto">xref <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="175624003" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/14179" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/14179/hovercard" href="https://github.com/pandas-dev/pandas/issues/14179">#14179</a><br>
xref <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="137459758" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/12499" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/12499/hovercard" href="https://github.com/pandas-dev/pandas/issues/12499">#12499</a><br>
xref <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="269507526" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/18027" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/18027/hovercard" href="https://github.com/pandas-dev/pandas/issues/18027">#18027</a></p>
<p dir="auto"><a href="http://stackoverflow.com/questions/23250333/in-pandas-dataframe-after-i-set-an-entire-column-i-cant-update-another-column" rel="nofollow">http://stackoverflow.com/questions/23250333/in-pandas-dataframe-after-i-set-an-entire-column-i-cant-update-another-column</a></p>
<p dir="auto">but <code class="notranslate">.loc</code> works</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [50]: df = pd.DataFrame(index=pd.date_range(start,periods=1), columns=['timenow','Live'])

In [51]: df.at[start,'timenow'] = datetime.today() # initial value

In [52]: df
Out[52]: 
                              timenow Live
2014-04-01 2014-04-23 12:42:38.883082  NaN

[1 rows x 2 columns]

In [53]: df._data
Out[53]: 
BlockManager
Items: Index([u'timenow', u'Live'], dtype='object')
Axis 1: &lt;class 'pandas.tseries.index.DatetimeIndex'&gt;
[2014-04-01]
Length: 1, Freq: D, Timezone: None
ObjectBlock: [timenow, Live], 2 x 1, dtype: object

In [54]: df = pd.DataFrame(index=pd.date_range(start,periods=1), columns=['timenow','Live'])

In [55]: df.loc[start,'timenow'] = datetime.today() # initial value

In [56]: df
Out[56]: 
                              timenow Live
2014-04-01 2014-04-23 12:43:00.554915  NaT

[1 rows x 2 columns]

In [57]: df._data
Out[57]: 
BlockManager
Items: Index([u'timenow', u'Live'], dtype='object')
Axis 1: &lt;class 'pandas.tseries.index.DatetimeIndex'&gt;
[2014-04-01]
Length: 1, Freq: D, Timezone: None
DatetimeBlock: [timenow, Live], 2 x 1, dtype: datetime64[ns]
"><pre class="notranslate"><code class="notranslate">In [50]: df = pd.DataFrame(index=pd.date_range(start,periods=1), columns=['timenow','Live'])

In [51]: df.at[start,'timenow'] = datetime.today() # initial value

In [52]: df
Out[52]: 
                              timenow Live
2014-04-01 2014-04-23 12:42:38.883082  NaN

[1 rows x 2 columns]

In [53]: df._data
Out[53]: 
BlockManager
Items: Index([u'timenow', u'Live'], dtype='object')
Axis 1: &lt;class 'pandas.tseries.index.DatetimeIndex'&gt;
[2014-04-01]
Length: 1, Freq: D, Timezone: None
ObjectBlock: [timenow, Live], 2 x 1, dtype: object

In [54]: df = pd.DataFrame(index=pd.date_range(start,periods=1), columns=['timenow','Live'])

In [55]: df.loc[start,'timenow'] = datetime.today() # initial value

In [56]: df
Out[56]: 
                              timenow Live
2014-04-01 2014-04-23 12:43:00.554915  NaT

[1 rows x 2 columns]

In [57]: df._data
Out[57]: 
BlockManager
Items: Index([u'timenow', u'Live'], dtype='object')
Axis 1: &lt;class 'pandas.tseries.index.DatetimeIndex'&gt;
[2014-04-01]
Length: 1, Freq: D, Timezone: None
DatetimeBlock: [timenow, Live], 2 x 1, dtype: datetime64[ns]

</code></pre></div>