A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pandas-dev/pandas/issues/2578 below:

should .ix allow partial setting? · Issue #2578 · pandas-dev/pandas · GitHub

Skip to content Navigation Menu

Saved searches Use saved searches to filter your results more quickly

Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert Additional navigation options

BUG/ENH: should .ix allow partial setting? #2578

Description

related to GH #2033

In [27]: df = pd.DataFrame(np.random.rand(4,2),index=pd.date_range('2001/1/12',periods=4),columns=['A','B'])

In [28]: df
Out[28]: 
                   A         B
2001-01-12  0.861201  0.530351
2001-01-13  0.434518  0.692022
2001-01-14  0.794237  0.912073
2001-01-15  0.421282  0.930005

In [29]: df.ix[:,'B'] = df.ix[:,'A'].copy()

In [30]: df.ix[:,'C'] = df.ix[:,'A'].copy()
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-30-2107107d0bd8> in <module>()
----> 1 df.ix[:,'C'] = df.ix[:,'A'].copy()


/usr/local/lib/python2.7/site-packages/pandas-0.10.0-py2.7-linux-x86_64.egg/pandas/core/index.pyc in get_loc(self, key)
    714         loc : int if unique index, possibly slice or mask if not
    715         """
--> 716         return self._engine.get_loc(key)
    717 
    718     def get_value(self, series, key):

KeyError: 'C'

of course in this case df['C'] = df.ix[:,'A'].copy() accomplishes this

Panel example: have to transpose, setitem, then transpose back to accomplish this

In [46]: p = pd.Panel(np.random.rand(2,4,2),items=['Item1','Item2'],major_axis=pd.date_range('2001/1/12',periods=4),minor_axis=['A','B'])

In [47]: p
Out[47]: 
<class 'pandas.core.panel.Panel'>
Dimensions: 2 (items) x 4 (major_axis) x 2 (minor_axis)
Items axis: Item1 to Item2
Major_axis axis: 2001-01-12 00:00:00 to 2001-01-15 00:00:00
Minor_axis axis: A to B

In [48]: pt = p.transpose(2,1,0)

In [49]: pt
Out[49]: 
<class 'pandas.core.panel.Panel'>
Dimensions: 2 (items) x 4 (major_axis) x 2 (minor_axis)
Items axis: A to B
Major_axis axis: 2001-01-12 00:00:00 to 2001-01-15 00:00:00
Minor_axis axis: Item1 to Item2

In [50]: pt['C'] = p.ix[:,:,'B'].copy()

In [51]: pt.transpose(2,1,0)
Out[51]: 
<class 'pandas.core.panel.Panel'>
Dimensions: 2 (items) x 4 (major_axis) x 3 (minor_axis)
Items axis: Item1 to Item2
Major_axis axis: 2001-01-12 00:00:00 to 2001-01-15 00:00:00
Minor_axis axis: A to C

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4