Closed
Description
Assignment to multiple columns of a :class:`DataFrame` when some of the columns do not exist would previously assign the values to the last column. Now, new columns would be constructed with the right values.
.. ipython:: python
df = pd.DataFrame({'a': [0, 1, 2], 'b': [3, 4, 5]})
df
*Previous behavior*:
.. code-block:: ipython
In [3]: df[['a', 'c']] = 1
In [4]: df
Out[4]:
a b
0 1 1
1 1 1
2 1 1
*New behavior*:
.. ipython:: python
df[['a', 'c']] = 1
df
import pandas as pd
df = pd.DataFrame({'a': [1, 2]})
df['b'] = 3 # creates column 'b'
df[['a', 'b']] = 4 # assigns to columns 'a' and 'b'
df[['c', 'd']] = 5 # KeyError: "['c' 'd'] not in index" !
df[['b', 'c']] = 6 # KeyError: "['c'] not in index" !
I would have expected all the above cases to work, but for some reason the last two fail. New column creation only seems to work for a single column, whilst multiple-column assignment works only if all columns exist.
INSTALLED VERSIONS
python: 3.5.1.final.0
python-bits: 64
pandas: 0.18.1
numpy: 1.11.1