<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="# Your code here
import pandas as pd
df = pd.DataFrame([[1,2],[1,2]],columns=['a','b'])
print df.apply(lambda x: {'s':x['a']+x['b']},1)
################
# (AS EXPECTED)
# output: 
# 0    {u's': 3}
# 1    {u's': 3}
# dtype: object
################

# add one new column with type Timestamp
df['tm'] = [pd.Timestamp('2017-05-01 00:00:00'),pd.Timestamp('2017-05-02 00:00:00')]
print df.apply(lambda x: {'s':x['a']+x['b']},1)

################
#(WRONG OUTPUT)
# output: 
#       a  b   tm
# 0   NaN NaN NaN
# 1   NaN NaN NaN
################
"><pre class="notranslate"><span class="pl-c"># Your code here</span>
<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-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>([[<span class="pl-c1">1</span>,<span class="pl-c1">2</span>],[<span class="pl-c1">1</span>,<span class="pl-c1">2</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-k">print</span> <span class="pl-s1">df</span>.<span class="pl-en">apply</span>(<span class="pl-k">lambda</span> <span class="pl-s1">x</span>: {<span class="pl-s">'s'</span>:<span class="pl-s1">x</span>[<span class="pl-s">'a'</span>]<span class="pl-c1">+</span><span class="pl-s1">x</span>[<span class="pl-s">'b'</span>]},<span class="pl-c1">1</span>)
<span class="pl-c">################</span>
<span class="pl-c"># (AS EXPECTED)</span>
<span class="pl-c"># output: </span>
<span class="pl-c"># 0    {u's': 3}</span>
<span class="pl-c"># 1    {u's': 3}</span>
<span class="pl-c"># dtype: object</span>
<span class="pl-c">################</span>

<span class="pl-c"># add one new column with type Timestamp</span>
<span class="pl-s1">df</span>[<span class="pl-s">'tm'</span>] <span class="pl-c1">=</span> [<span class="pl-s1">pd</span>.<span class="pl-v">Timestamp</span>(<span class="pl-s">'2017-05-01 00:00:00'</span>),<span class="pl-s1">pd</span>.<span class="pl-v">Timestamp</span>(<span class="pl-s">'2017-05-02 00:00:00'</span>)]
<span class="pl-k">print</span> <span class="pl-s1">df</span>.<span class="pl-en">apply</span>(<span class="pl-k">lambda</span> <span class="pl-s1">x</span>: {<span class="pl-s">'s'</span>:<span class="pl-s1">x</span>[<span class="pl-s">'a'</span>]<span class="pl-c1">+</span><span class="pl-s1">x</span>[<span class="pl-s">'b'</span>]},<span class="pl-c1">1</span>)

<span class="pl-c">################</span>
<span class="pl-c">#(WRONG OUTPUT)</span>
<span class="pl-c"># output: </span>
<span class="pl-c">#       a  b   tm</span>
<span class="pl-c"># 0   NaN NaN NaN</span>
<span class="pl-c"># 1   NaN NaN NaN</span>
<span class="pl-c">################</span></pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">when the return type of apply function is dict, if a new column with type Timestamp is added to the dataframe, the result will be unexpected even if the apply function is unchanged</p>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
<p dir="auto">commit: None<br>
python: 2.7.13.final.0<br>
python-bits: 64<br>
OS: Darwin<br>
OS-release: 14.5.0<br>
machine: x86_64<br>
processor: i386<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: zh_CN.UTF-8<br>
LOCALE: None.None</p>
<p dir="auto">pandas: 0.20.3<br>
pytest: None<br>
pip: 9.0.1<br>
setuptools: 36.0.1<br>
Cython: 0.25.2<br>
numpy: 1.13.1<br>
scipy: 0.19.1<br>
xarray: None<br>
IPython: 5.4.1<br>
sphinx: None<br>
patsy: 0.4.1<br>
dateutil: 2.6.1<br>
pytz: 2017.2<br>
blosc: None<br>
bottleneck: None<br>
tables: None<br>
numexpr: None<br>
feather: None<br>
matplotlib: 2.0.2<br>
openpyxl: None<br>
xlrd: 1.0.0<br>
xlwt: None<br>
xlsxwriter: 0.9.6<br>
lxml: None<br>
bs4: None<br>
html5lib: 0.999999999<br>
sqlalchemy: 1.1.14<br>
pymysql: 0.7.11.None<br>
psycopg2: None<br>
jinja2: 2.9.6<br>
s3fs: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>
<p dir="auto">Hello guys, I'm using the apply method with axis=1 argument and returning a list for each row. The weird thing is when the length of this list is equal to the number of features in the original dataframe, this apply returns another dataframe, and a series if anything else. I don't know if this is intended, but it was very unexpected.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import numpy as np
import pandas as pd

df = pd.DataFrame(np.random.randn(6, 3), columns=['A', 'B', 'C'])

ans1 = df.apply(lambda x: [1, 2, 3], axis=1)
ans2 = df.apply(lambda x: [1, 2], axis=1)

assert type(ans1) is pd.DataFrame
assert type(ans2) is pd.Series"><pre class="notranslate"><code class="notranslate">import numpy as np
import pandas as pd

df = pd.DataFrame(np.random.randn(6, 3), columns=['A', 'B', 'C'])

ans1 = df.apply(lambda x: [1, 2, 3], axis=1)
ans2 = df.apply(lambda x: [1, 2], axis=1)

assert type(ans1) is pd.DataFrame
assert type(ans2) is pd.Series
</code></pre></div>