Closed
Description
When concatenating a dataframe and series along axis 1, the docs indicate that the series will be treated as a series with a single column matching the column name. Based on this, I'd expect similar behavior (or an error) when concatenating a named series with a dataframe along axis 0. However, this seems to result in a new numeric column for the named series instead of converting the series to a dataframe:
In [10]: pd.__version__
Out[10]: '0.19.1'
In [11]: df = pd.DataFrame({'x': range(5), 'y': range(5), 'z': range(5)})
In [12]: pd.concat([df, df.x])
Out[12]:
x y z 0
0 0.0 0.0 0.0 NaN
1 1.0 1.0 1.0 NaN
2 2.0 2.0 2.0 NaN
3 3.0 3.0 3.0 NaN
4 4.0 4.0 4.0 NaN
0 NaN NaN NaN 0.0
1 NaN NaN NaN 1.0
2 NaN NaN NaN 2.0
3 NaN NaN NaN 3.0
4 NaN NaN NaN 4.0
In [13]: pd.concat([df, df.x.to_frame()])
Out[13]:
x y z
0 0 0.0 0.0
1 1 1.0 1.0
2 2 2.0 2.0
3 3 3.0 3.0
4 4 4.0 4.0
0 0 NaN NaN
1 1 NaN NaN
2 2 NaN NaN
3 3 NaN NaN
4 4 NaN NaN
I'd expect either an error, or the behavior in out[13].