Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assign column values to non-unique DataFrame #4067

Closed
joeb1415 opened this issue Jun 28, 2013 · 2 comments
Closed

Assign column values to non-unique DataFrame #4067

joeb1415 opened this issue Jun 28, 2013 · 2 comments

Comments

@joeb1415
Copy link

Related: #2862

In [1]: from pandas import DataFrame

In [2]: df = DataFrame([[1,2],[3,4]], index=[0,0], columns=[0,0])

In [3]: df
Out[3]:
   0  0
0  1  2
0  3  4

In [4]: df.index=[0,1]

In [5]: df
Out[5]:
   0  0
0  1  2
1  3  4

In [6]: df.columns=[0,1]
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-6-538dde7e36b8> in <module>()
----> 1 df.columns=[0,1]

C:\Python27\lib\site-packages\pandas\core\frame.pyc in __setattr__(self, name, value)
   2016                 existing = getattr(self, name)
   2017                 if isinstance(existing, Index):
-> 2018                     super(DataFrame, self).__setattr__(name, value)
   2019                 elif name in self.columns:
   2020                     self[name] = value

C:\Python27\lib\site-packages\pandas\lib.pyd in pandas.lib.AxisProperty.__set__ (pandas\lib.c:28444)()

C:\Python27\lib\site-packages\pandas\core\generic.pyc in _set_axis(self, axis, labels)
    557
    558     def _set_axis(self, axis, labels):
--> 559         self._data.set_axis(axis, labels)
    560         self._clear_item_cache()
    561

C:\Python27\lib\site-packages\pandas\core\internals.pyc in set_axis(self, axis, value)
    920         if axis == 0:
    921             for block in self.blocks:
--> 922                 block.set_ref_items(self.items, maybe_rename=True)
    923
    924     # make items read only for now

C:\Python27\lib\site-packages\pandas\core\internals.pyc in set_ref_items(self, ref_items, maybe_rename)
     72             raise AssertionError('block ref_items must be an Index')
     73         if maybe_rename:
---> 74             self.items = ref_items.take(self.ref_locs)
     75         self.ref_items = ref_items
     76

C:\Python27\lib\site-packages\pandas\core\internals.pyc in ref_locs(self)
     57     def ref_locs(self):
     58         if self._ref_locs is None:
---> 59             indexer = self.ref_items.get_indexer(self.items)
     60             indexer = com._ensure_platform_int(indexer)
     61             if (indexer == -1).any():

C:\Python27\lib\site-packages\pandas\core\index.pyc in get_indexer(self, target, method, limit)
    847
    848         if not self.is_unique:
--> 849             raise Exception('Reindexing only valid with uniquely valued Index '
    850                             'objects')
    851

Exception: Reindexing only valid with uniquely valued Index objects
@jreback
Copy link
Contributor

jreback commented Jun 28, 2013

closed by #3483 among others and functional in 0.12

pls try with master

@jreback
Copy link
Contributor

jreback commented Jun 28, 2013

In [9]: pd.__version__
Out[9]: '0.12.0.dev-f09a03c'

In [10]: df = DataFrame([[1,2],[3,4]], index=[0,0], columns=[0,0])

In [11]: df.index=[0,1]

In [12]: df.columns=[0,1]

In [13]: df
Out[13]: 
   0  1
0  1  2
1  3  4

@jreback jreback closed this as completed Jun 28, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants