<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="
df = pd.DataFrame(list(range(9)), pd.MultiIndex.from_product([['a', 'b', 'c'], [1, 2, 3]]), ['col'])
df.index
# MultiIndex(levels=[['a', 'b', 'c'], [1, 2, 3]],
#            labels=[[0, 0, 0, 1, 1, 1, 2, 2, 2], [0, 1, 2, 0, 1, 2, 0, 1, 2]])
df.to_parquet('test.parquet', engine='fastparquet')
df1 = pd.read_parquet('test.parquet')
df1.index
# MultiIndex(levels=[['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c'], [1, 2, 3, 1, 2, 3, 1, 2, 3]],
#            labels=[[0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8]],
#            names=['level_0', 'level_1'])
# 
df.loc['a', 1]
# col    0
# Name: (a, 1), dtype: int64
df1.loc['a', 1]
# Traceback (most recent call last):
#   File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
#   File &quot;/usr/local/lib/python3.7/site-packages/pandas/core/indexing.py&quot;, line 1472, in __getitem__
#     return self._getitem_tuple(key)
#   File &quot;/usr/local/lib/python3.7/site-packages/pandas/core/indexing.py&quot;, line 870, in _getitem_tuple
#     return self._getitem_lowerdim(tup)
#   File &quot;/usr/local/lib/python3.7/site-packages/pandas/core/indexing.py&quot;, line 1027, in _getitem_lowerdim
#     return getattr(section, self.name)[new_key]
#   File &quot;/usr/local/lib/python3.7/site-packages/pandas/core/indexing.py&quot;, line 1472, in __getitem__
#     return self._getitem_tuple(key)
#   File &quot;/usr/local/lib/python3.7/site-packages/pandas/core/indexing.py&quot;, line 870, in _getitem_tuple
#     return self._getitem_lowerdim(tup)
#   File &quot;/usr/local/lib/python3.7/site-packages/pandas/core/indexing.py&quot;, line 998, in _getitem_lowerdim
#     section = self._getitem_axis(key, axis=i)
#   File &quot;/usr/local/lib/python3.7/site-packages/pandas/core/indexing.py&quot;, line 1911, in _getitem_axis
#     self._validate_key(key, axis)
#   File &quot;/usr/local/lib/python3.7/site-packages/pandas/core/indexing.py&quot;, line 1788, in _validate_key
#     key = self._convert_scalar_indexer(key, axis)
#   File &quot;/usr/local/lib/python3.7/site-packages/pandas/core/indexing.py&quot;, line 261, in _convert_scalar_indexer
#     return ax._convert_scalar_indexer(key, kind=self.name)
#   File &quot;/usr/local/lib/python3.7/site-packages/pandas/core/indexes/base.py&quot;, line 1679, in _convert_scalar_indexer
#     return self._invalid_indexer('label', key)
#   File &quot;/usr/local/lib/python3.7/site-packages/pandas/core/indexes/base.py&quot;, line 1863, in _invalid_indexer
#     kind=type(key)))
# TypeError: cannot do label indexing on &lt;class 'pandas.core.indexes.base.Index'&gt; with these indexers [1] of &lt;class 'int'&gt;
"><pre class="notranslate"><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-en">list</span>(<span class="pl-en">range</span>(<span class="pl-c1">9</span>)), <span class="pl-s1">pd</span>.<span class="pl-v">MultiIndex</span>.<span class="pl-en">from_product</span>([[<span class="pl-s">'a'</span>, <span class="pl-s">'b'</span>, <span class="pl-s">'c'</span>], [<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>]]), [<span class="pl-s">'col'</span>])
<span class="pl-s1">df</span>.<span class="pl-s1">index</span>
<span class="pl-c"># MultiIndex(levels=[['a', 'b', 'c'], [1, 2, 3]],</span>
<span class="pl-c">#            labels=[[0, 0, 0, 1, 1, 1, 2, 2, 2], [0, 1, 2, 0, 1, 2, 0, 1, 2]])</span>
<span class="pl-s1">df</span>.<span class="pl-en">to_parquet</span>(<span class="pl-s">'test.parquet'</span>, <span class="pl-s1">engine</span><span class="pl-c1">=</span><span class="pl-s">'fastparquet'</span>)
<span class="pl-s1">df1</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">read_parquet</span>(<span class="pl-s">'test.parquet'</span>)
<span class="pl-s1">df1</span>.<span class="pl-s1">index</span>
<span class="pl-c"># MultiIndex(levels=[['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c'], [1, 2, 3, 1, 2, 3, 1, 2, 3]],</span>
<span class="pl-c">#            labels=[[0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3, 4, 5, 6, 7, 8]],</span>
<span class="pl-c">#            names=['level_0', 'level_1'])</span>
<span class="pl-c"># </span>
<span class="pl-s1">df</span>.<span class="pl-s1">loc</span>[<span class="pl-s">'a'</span>, <span class="pl-c1">1</span>]
<span class="pl-c"># col    0</span>
<span class="pl-c"># Name: (a, 1), dtype: int64</span>
<span class="pl-s1">df1</span>.<span class="pl-s1">loc</span>[<span class="pl-s">'a'</span>, <span class="pl-c1">1</span>]
<span class="pl-c"># Traceback (most recent call last):</span>
<span class="pl-c">#   File "&lt;stdin&gt;", line 1, in &lt;module&gt;</span>
<span class="pl-c">#   File "/usr/local/lib/python3.7/site-packages/pandas/core/indexing.py", line 1472, in __getitem__</span>
<span class="pl-c">#     return self._getitem_tuple(key)</span>
<span class="pl-c">#   File "/usr/local/lib/python3.7/site-packages/pandas/core/indexing.py", line 870, in _getitem_tuple</span>
<span class="pl-c">#     return self._getitem_lowerdim(tup)</span>
<span class="pl-c">#   File "/usr/local/lib/python3.7/site-packages/pandas/core/indexing.py", line 1027, in _getitem_lowerdim</span>
<span class="pl-c">#     return getattr(section, self.name)[new_key]</span>
<span class="pl-c">#   File "/usr/local/lib/python3.7/site-packages/pandas/core/indexing.py", line 1472, in __getitem__</span>
<span class="pl-c">#     return self._getitem_tuple(key)</span>
<span class="pl-c">#   File "/usr/local/lib/python3.7/site-packages/pandas/core/indexing.py", line 870, in _getitem_tuple</span>
<span class="pl-c">#     return self._getitem_lowerdim(tup)</span>
<span class="pl-c">#   File "/usr/local/lib/python3.7/site-packages/pandas/core/indexing.py", line 998, in _getitem_lowerdim</span>
<span class="pl-c">#     section = self._getitem_axis(key, axis=i)</span>
<span class="pl-c">#   File "/usr/local/lib/python3.7/site-packages/pandas/core/indexing.py", line 1911, in _getitem_axis</span>
<span class="pl-c">#     self._validate_key(key, axis)</span>
<span class="pl-c">#   File "/usr/local/lib/python3.7/site-packages/pandas/core/indexing.py", line 1788, in _validate_key</span>
<span class="pl-c">#     key = self._convert_scalar_indexer(key, axis)</span>
<span class="pl-c">#   File "/usr/local/lib/python3.7/site-packages/pandas/core/indexing.py", line 261, in _convert_scalar_indexer</span>
<span class="pl-c">#     return ax._convert_scalar_indexer(key, kind=self.name)</span>
<span class="pl-c">#   File "/usr/local/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 1679, in _convert_scalar_indexer</span>
<span class="pl-c">#     return self._invalid_indexer('label', key)</span>
<span class="pl-c">#   File "/usr/local/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 1863, in _invalid_indexer</span>
<span class="pl-c">#     kind=type(key)))</span>
<span class="pl-c"># TypeError: cannot do label indexing on &lt;class 'pandas.core.indexes.base.Index'&gt; with these indexers [1] of &lt;class 'int'&gt;</span></pre></div>
<h4 dir="auto">Problem description</h4>
<ol dir="auto">
<li>When importing <code class="notranslate">DataFrame</code> by <code class="notranslate">read_parquet()</code>, <code class="notranslate">MultiIndex.levels</code> becomes large and duplicated.</li>
<li>The imported <code class="notranslate">DataFrame</code> fails indexing.</li>
</ol>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
<h2 dir="auto">[paste the output of <code class="notranslate">pd.show_versions()</code> here below this line]<br>
INSTALLED VERSIONS</h2>
<p dir="auto">commit: None<br>
python: 3.7.0.final.0<br>
python-bits: 64<br>
OS: Darwin<br>
OS-release: 17.7.0<br>
machine: x86_64<br>
processor: i386<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: zh_CN.UTF-8<br>
LOCALE: zh_CN.UTF-8</p>
<p dir="auto">pandas: 0.23.3<br>
pytest: None<br>
pip: 10.0.1<br>
setuptools: 39.2.0<br>
Cython: 0.28.4<br>
numpy: 1.14.5<br>
scipy: 1.1.0<br>
pyarrow: None<br>
xarray: None<br>
IPython: None<br>
sphinx: None<br>
patsy: None<br>
dateutil: 2.7.3<br>
pytz: 2018.5<br>
blosc: None<br>
bottleneck: None<br>
tables: None<br>
numexpr: None<br>
feather: None<br>
matplotlib: None<br>
openpyxl: None<br>
xlrd: None<br>
xlwt: None<br>
xlsxwriter: None<br>
lxml: None<br>
bs4: 4.6.0<br>
html5lib: None<br>
sqlalchemy: None<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: None<br>
s3fs: None<br>
fastparquet: 0.1.5<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
<blockquote>
<blockquote>
<blockquote>
</blockquote>
</blockquote>
</blockquote>
</details>
<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="In [2]: df = pd.DataFrame(index=range(3), columns=['A', 'B', 'C', 'D', 'E', 'F'])

In [3]: df.loc[0, ['A', 'D']] = (1,2)

In [4]: df.loc[:, ['B', 'E']] = (1,2)

In [5]: df[['C', 'F']] = (1,2)

In [6]: df
Out[6]: 
     A  B  C    D  E  F
0    1  1  1    2  2  2
1  NaN  1  1  NaN  2  2
2  NaN  1  1  NaN  2  2

In [7]: dfdup = pd.DataFrame(index=range(3), columns=['A', 'B', 'C']*2)

In [8]: dfdup.loc[0, 'A'] = (1,2) # Works

In [9]: dfdup.loc[:, 'B'] = (1,2) # Works

In [10]: dfdup['C'] = (1,2) # Fails
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
&lt;ipython-input-10-17d5611af828&gt; in &lt;module&gt;()
----&gt; 1 dfdup['C'] = (1,2)

/home/pietro/nobackup/repo/pandas/pandas/core/frame.py in __setitem__(self, key, value)
   2421         else:
   2422             # set column
-&gt; 2423             self._set_item(key, value)
   2424 
   2425     def _setitem_slice(self, key, value):

/home/pietro/nobackup/repo/pandas/pandas/core/frame.py in _set_item(self, key, value)
   2487 
   2488         self._ensure_valid_index(value)
-&gt; 2489         value = self._sanitize_column(key, value)
   2490         NDFrame._set_item(self, key, value)
   2491 

/home/pietro/nobackup/repo/pandas/pandas/core/frame.py in _sanitize_column(self, key, value, broadcast)
   2658 
   2659             # turn me into an ndarray
-&gt; 2660             value = _sanitize_index(value, self.index, copy=False)
   2661             if not isinstance(value, (np.ndarray, Index)):
   2662                 if isinstance(value, list) and len(value) &gt; 0:

/home/pietro/nobackup/repo/pandas/pandas/core/series.py in _sanitize_index(data, index, copy)
   2847 
   2848     if len(data) != len(index):
-&gt; 2849         raise ValueError('Length of values does not match length of ' 'index')
   2850 
   2851     if isinstance(data, PeriodIndex):

ValueError: Length of values does not match length of index

In [11]: dfdup
Out[11]: 
     A  B    C    A  B    C
0    1  1  NaN    2  2  NaN
1  NaN  1  NaN  NaN  2  NaN
2  NaN  1  NaN  NaN  2  NaN"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">2</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-s1">index</span><span class="pl-c1">=</span><span class="pl-en">range</span>(<span class="pl-c1">3</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-s">'D'</span>, <span class="pl-s">'E'</span>, <span class="pl-s">'F'</span>])

<span class="pl-v">In</span> [<span class="pl-c1">3</span>]: <span class="pl-s1">df</span>.<span class="pl-s1">loc</span>[<span class="pl-c1">0</span>, [<span class="pl-s">'A'</span>, <span class="pl-s">'D'</span>]] <span class="pl-c1">=</span> (<span class="pl-c1">1</span>,<span class="pl-c1">2</span>)

<span class="pl-v">In</span> [<span class="pl-c1">4</span>]: <span class="pl-s1">df</span>.<span class="pl-s1">loc</span>[:, [<span class="pl-s">'B'</span>, <span class="pl-s">'E'</span>]] <span class="pl-c1">=</span> (<span class="pl-c1">1</span>,<span class="pl-c1">2</span>)

<span class="pl-v">In</span> [<span class="pl-c1">5</span>]: <span class="pl-s1">df</span>[[<span class="pl-s">'C'</span>, <span class="pl-s">'F'</span>]] <span class="pl-c1">=</span> (<span class="pl-c1">1</span>,<span class="pl-c1">2</span>)

<span class="pl-v">In</span> [<span class="pl-c1">6</span>]: <span class="pl-s1">df</span>
<span class="pl-v">Out</span>[<span class="pl-c1">6</span>]: 
     <span class="pl-v">A</span>  <span class="pl-v">B</span>  <span class="pl-v">C</span>    <span class="pl-v">D</span>  <span class="pl-v">E</span>  <span class="pl-v">F</span>
<span class="pl-c1">0</span>    <span class="pl-c1">1</span>  <span class="pl-c1">1</span>  <span class="pl-c1">1</span>    <span class="pl-c1">2</span>  <span class="pl-c1">2</span>  <span class="pl-c1">2</span>
<span class="pl-c1">1</span>  <span class="pl-v">NaN</span>  <span class="pl-c1">1</span>  <span class="pl-c1">1</span>  <span class="pl-v">NaN</span>  <span class="pl-c1">2</span>  <span class="pl-c1">2</span>
<span class="pl-c1">2</span>  <span class="pl-v">NaN</span>  <span class="pl-c1">1</span>  <span class="pl-c1">1</span>  <span class="pl-v">NaN</span>  <span class="pl-c1">2</span>  <span class="pl-c1">2</span>

<span class="pl-v">In</span> [<span class="pl-c1">7</span>]: <span class="pl-s1">dfdup</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>(<span class="pl-s1">index</span><span class="pl-c1">=</span><span class="pl-en">range</span>(<span class="pl-c1">3</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-c1">*</span><span class="pl-c1">2</span>)

<span class="pl-v">In</span> [<span class="pl-c1">8</span>]: <span class="pl-s1">dfdup</span>.<span class="pl-s1">loc</span>[<span class="pl-c1">0</span>, <span class="pl-s">'A'</span>] <span class="pl-c1">=</span> (<span class="pl-c1">1</span>,<span class="pl-c1">2</span>) <span class="pl-c"># Works</span>

<span class="pl-v">In</span> [<span class="pl-c1">9</span>]: <span class="pl-s1">dfdup</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-c1">2</span>) <span class="pl-c"># Works</span>

<span class="pl-v">In</span> [<span class="pl-c1">10</span>]: <span class="pl-s1">dfdup</span>[<span class="pl-s">'C'</span>] <span class="pl-c1">=</span> (<span class="pl-c1">1</span>,<span class="pl-c1">2</span>) <span class="pl-c"># Fails</span>
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span>
<span class="pl-v">ValueError</span>                                <span class="pl-v">Traceback</span> (<span class="pl-s1">most</span> <span class="pl-s1">recent</span> <span class="pl-s1">call</span> <span class="pl-s1">last</span>)
<span class="pl-c1">&lt;</span><span class="pl-s1">ipython</span><span class="pl-c1">-</span><span class="pl-s1">input</span><span class="pl-c1">-</span><span class="pl-c1">10</span><span class="pl-c1">-</span><span class="pl-c1">17</span><span class="pl-s1">d5611af828</span><span class="pl-c1">&gt;</span> <span class="pl-s1">in</span> <span class="pl-c1">&lt;</span><span class="pl-s1">module</span><span class="pl-c1">&gt;</span>()
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">1</span> <span class="pl-s1">dfdup</span>[<span class="pl-s">'C'</span>] <span class="pl-c1">=</span> (<span class="pl-c1">1</span>,<span class="pl-c1">2</span>)

<span class="pl-c1">/</span><span class="pl-s1">home</span><span class="pl-c1">/</span><span class="pl-s1">pietro</span><span class="pl-c1">/</span><span class="pl-s1">nobackup</span><span class="pl-c1">/</span><span class="pl-s1">repo</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">core</span><span class="pl-c1">/</span><span class="pl-s1">frame</span>.<span class="pl-s1">py</span> <span class="pl-c1">in</span> <span class="pl-en">__setitem__</span>(<span class="pl-s1">self</span>, <span class="pl-s1">key</span>, <span class="pl-s1">value</span>)
   <span class="pl-c1">2421</span>         <span class="pl-s1">else</span>:
   <span class="pl-c1">2422</span>             <span class="pl-c"># set column</span>
<span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">2423</span>             <span class="pl-s1">self</span>.<span class="pl-en">_set_item</span>(<span class="pl-s1">key</span>, <span class="pl-s1">value</span>)
   <span class="pl-c1">2424</span> 
   <span class="pl-c1">2425</span>     <span class="pl-k">def</span> <span class="pl-en">_setitem_slice</span>(<span class="pl-s1">self</span>, <span class="pl-s1">key</span>, <span class="pl-s1">value</span>):

<span class="pl-c1">/</span><span class="pl-s1">home</span><span class="pl-c1">/</span><span class="pl-s1">pietro</span><span class="pl-c1">/</span><span class="pl-s1">nobackup</span><span class="pl-c1">/</span><span class="pl-s1">repo</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">core</span><span class="pl-c1">/</span><span class="pl-s1">frame</span>.<span class="pl-s1">py</span> <span class="pl-c1">in</span> <span class="pl-en">_set_item</span>(<span class="pl-s1">self</span>, <span class="pl-s1">key</span>, <span class="pl-s1">value</span>)
   <span class="pl-c1">2487</span> 
   <span class="pl-c1">2488</span>         <span class="pl-s1">self</span>.<span class="pl-en">_ensure_valid_index</span>(<span class="pl-s1">value</span>)
<span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">2489</span>         <span class="pl-s1">value</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-en">_sanitize_column</span>(<span class="pl-s1">key</span>, <span class="pl-s1">value</span>)
   <span class="pl-c1">2490</span>         <span class="pl-v">NDFrame</span>.<span class="pl-en">_set_item</span>(<span class="pl-s1">self</span>, <span class="pl-s1">key</span>, <span class="pl-s1">value</span>)
   <span class="pl-c1">2491</span> 

<span class="pl-c1">/</span><span class="pl-s1">home</span><span class="pl-c1">/</span><span class="pl-s1">pietro</span><span class="pl-c1">/</span><span class="pl-s1">nobackup</span><span class="pl-c1">/</span><span class="pl-s1">repo</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">core</span><span class="pl-c1">/</span><span class="pl-s1">frame</span>.<span class="pl-s1">py</span> <span class="pl-c1">in</span> <span class="pl-en">_sanitize_column</span>(<span class="pl-s1">self</span>, <span class="pl-s1">key</span>, <span class="pl-s1">value</span>, <span class="pl-s1">broadcast</span>)
   <span class="pl-c1">2658</span> 
   <span class="pl-c1">2659</span>             <span class="pl-c"># turn me into an ndarray</span>
<span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">2660</span>             <span class="pl-s1">value</span> <span class="pl-c1">=</span> <span class="pl-en">_sanitize_index</span>(<span class="pl-s1">value</span>, <span class="pl-s1">self</span>.<span class="pl-s1">index</span>, <span class="pl-s1">copy</span><span class="pl-c1">=</span><span class="pl-c1">False</span>)
   <span class="pl-c1">2661</span>             <span class="pl-k">if</span> <span class="pl-c1">not</span> <span class="pl-en">isinstance</span>(<span class="pl-s1">value</span>, (<span class="pl-s1">np</span>.<span class="pl-s1">ndarray</span>, <span class="pl-v">Index</span>)):
   <span class="pl-c1">2662</span>                 <span class="pl-k">if</span> <span class="pl-en">isinstance</span>(<span class="pl-s1">value</span>, <span class="pl-s1">list</span>) <span class="pl-c1">and</span> <span class="pl-en">len</span>(<span class="pl-s1">value</span>) <span class="pl-c1">&gt;</span> <span class="pl-c1">0</span>:

<span class="pl-c1">/</span><span class="pl-s1">home</span><span class="pl-c1">/</span><span class="pl-s1">pietro</span><span class="pl-c1">/</span><span class="pl-s1">nobackup</span><span class="pl-c1">/</span><span class="pl-s1">repo</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">core</span><span class="pl-c1">/</span><span class="pl-s1">series</span>.<span class="pl-s1">py</span> <span class="pl-c1">in</span> <span class="pl-en">_sanitize_index</span>(<span class="pl-s1">data</span>, <span class="pl-s1">index</span>, <span class="pl-s1">copy</span>)
   <span class="pl-c1">2847</span> 
   <span class="pl-c1">2848</span>     <span class="pl-k">if</span> <span class="pl-en">len</span>(<span class="pl-s1">data</span>) <span class="pl-c1">!=</span> <span class="pl-en">len</span>(<span class="pl-s1">index</span>):
<span class="pl-c1">-&gt;</span> <span class="pl-c1">2849</span>         <span class="pl-k">raise</span> <span class="pl-v">ValueError</span>(<span class="pl-s">'Length of values does not match length of '</span> <span class="pl-s">'index'</span>)
   <span class="pl-c1">2850</span> 
   <span class="pl-c1">2851</span>     <span class="pl-k">if</span> <span class="pl-en">isinstance</span>(<span class="pl-s1">data</span>, <span class="pl-v">PeriodIndex</span>):

<span class="pl-v">ValueError</span>: <span class="pl-v">Length</span> <span class="pl-s1">of</span> <span class="pl-s1">values</span> <span class="pl-s1">does</span> <span class="pl-c1">not</span> <span class="pl-s1">match</span> <span class="pl-s1">length</span> <span class="pl-s1">of</span> <span class="pl-s1">index</span>

<span class="pl-v">In</span> [<span class="pl-c1">11</span>]: <span class="pl-s1">dfdup</span>
<span class="pl-v">Out</span>[<span class="pl-c1">11</span>]: 
     <span class="pl-v">A</span>  <span class="pl-v">B</span>    <span class="pl-v">C</span>    <span class="pl-v">A</span>  <span class="pl-v">B</span>    <span class="pl-v">C</span>
<span class="pl-c1">0</span>    <span class="pl-c1">1</span>  <span class="pl-c1">1</span>  <span class="pl-v">NaN</span>    <span class="pl-c1">2</span>  <span class="pl-c1">2</span>  <span class="pl-v">NaN</span>
<span class="pl-c1">1</span>  <span class="pl-v">NaN</span>  <span class="pl-c1">1</span>  <span class="pl-v">NaN</span>  <span class="pl-v">NaN</span>  <span class="pl-c1">2</span>  <span class="pl-v">NaN</span>
<span class="pl-c1">2</span>  <span class="pl-v">NaN</span>  <span class="pl-c1">1</span>  <span class="pl-v">NaN</span>  <span class="pl-v">NaN</span>  <span class="pl-c1">2</span>  <span class="pl-v">NaN</span></pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">While <code class="notranslate">loc</code> correctly treats <code class="notranslate">A</code> as referring to two columns, <code class="notranslate">DataFrame[.]</code> sees one value only and raises. Note that <code class="notranslate">Series[.]</code> behaves correctly:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [12]: s = pd.Series(index=['A', 'B']*2)

In [13]: s.loc['A'] = (1,2)

In [14]: s
Out[14]: 
A    1.0
B    NaN
A    2.0
B    NaN
dtype: float64

In [15]: s['B'] = (1,2)

In [16]: s
Out[16]: 
A    1.0
B    1.0
A    2.0
B    2.0
dtype: float64"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">12</span>]: <span class="pl-s1">s</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">Series</span>(<span class="pl-s1">index</span><span class="pl-c1">=</span>[<span class="pl-s">'A'</span>, <span class="pl-s">'B'</span>]<span class="pl-c1">*</span><span class="pl-c1">2</span>)

<span class="pl-v">In</span> [<span class="pl-c1">13</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-c1">1</span>,<span class="pl-c1">2</span>)

<span class="pl-v">In</span> [<span class="pl-c1">14</span>]: <span class="pl-s1">s</span>
<span class="pl-v">Out</span>[<span class="pl-c1">14</span>]: 
<span class="pl-v">A</span>    <span class="pl-c1">1.0</span>
<span class="pl-v">B</span>    <span class="pl-v">NaN</span>
<span class="pl-v">A</span>    <span class="pl-c1">2.0</span>
<span class="pl-v">B</span>    <span class="pl-v">NaN</span>
<span class="pl-s1">dtype</span>: <span class="pl-s1">float64</span>

<span class="pl-v">In</span> [<span class="pl-c1">15</span>]: <span class="pl-s1">s</span>[<span class="pl-s">'B'</span>] <span class="pl-c1">=</span> (<span class="pl-c1">1</span>,<span class="pl-c1">2</span>)

<span class="pl-v">In</span> [<span class="pl-c1">16</span>]: <span class="pl-s1">s</span>
<span class="pl-v">Out</span>[<span class="pl-c1">16</span>]: 
<span class="pl-v">A</span>    <span class="pl-c1">1.0</span>
<span class="pl-v">B</span>    <span class="pl-c1">1.0</span>
<span class="pl-v">A</span>    <span class="pl-c1">2.0</span>
<span class="pl-v">B</span>    <span class="pl-c1">2.0</span>
<span class="pl-s1">dtype</span>: <span class="pl-s1">float64</span></pre></div>
<h4 dir="auto">Expected Output</h4>
<p dir="auto"><code class="notranslate">Out[6]</code> (except for column names, obviously)</p>
<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: Linux<br>
OS-release: 4.7.0-1-amd64<br>
machine: x86_64<br>
processor:<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: it_IT.utf8<br>
LOCALE: it_IT.UTF-8</p>
<p dir="auto">pandas: 0.19.0+605.gc081d5782<br>
pytest: 3.0.6<br>
pip: 9.0.1<br>
setuptools: 33.1.1<br>
Cython: 0.25.2<br>
numpy: 1.12.0<br>
scipy: 0.18.1<br>
xarray: None<br>
IPython: 5.1.0.dev<br>
sphinx: 1.4.9<br>
patsy: 0.3.0-dev<br>
dateutil: 2.5.3<br>
pytz: 2016.7<br>
blosc: None<br>
bottleneck: 1.2.0<br>
tables: 3.3.0<br>
numexpr: 2.6.1<br>
feather: 0.3.1<br>
matplotlib: 2.0.0<br>
openpyxl: 2.3.0<br>
xlrd: 1.0.0<br>
xlwt: 1.1.2<br>
xlsxwriter: 0.9.6<br>
lxml: 3.7.1<br>
bs4: 4.5.3<br>
html5lib: 0.999999999<br>
sqlalchemy: 1.0.15<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.8<br>
s3fs: None<br>
pandas_gbq: None<br>
pandas_datareader: 0.2.1</p>
</details>