Skip to content

Commit 0397d37

Browse files
committed
ENH: extensive indexing.py refactoring and implemented fancy/advanced indexing
fro Panel. address GH #118
1 parent bc1135f commit 0397d37

File tree

5 files changed

+466
-293
lines changed

5 files changed

+466
-293
lines changed

pandas/core/frame.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from pandas.core.daterange import DateRange
2626
from pandas.core.generic import AxisProperty, NDFrame
2727
from pandas.core.index import Index, MultiIndex, NULL_INDEX
28-
from pandas.core.indexing import _DataFrameIndexer, _maybe_droplevels
28+
from pandas.core.indexing import _NDFrameIndexer, _maybe_droplevels
2929
from pandas.core.internals import BlockManager, make_block, form_blocks
3030
from pandas.core.series import Series, _is_bool_indexer
3131
from pandas.util.decorators import deprecate
@@ -244,7 +244,7 @@ def _constructor(self):
244244
@property
245245
def ix(self):
246246
if self._ix is None:
247-
self._ix = _DataFrameIndexer(self)
247+
self._ix = _NDFrameIndexer(self)
248248

249249
return self._ix
250250

@@ -948,19 +948,30 @@ def pop(self, item):
948948
def _series(self):
949949
return self._data.get_series_dict()
950950

951-
def xs(self, key, copy=True):
951+
def xs(self, key, axis=0, copy=True):
952952
"""
953-
Returns a row (cross-section) from the DataFrame as a Series object
953+
Returns a cross-section (row or column) from the DataFrame as a Series
954+
object. Defaults to returning a row (axis 0)
954955
955956
Parameters
956957
----------
957958
key : object
958959
Some label contained in the index, or partially in a MultiIndex
960+
axis : int, default 0
961+
Axis to retrieve cross-section on
962+
copy : boolean, default True
963+
Whether to make a copy of the data
959964
960965
Returns
961966
-------
962967
xs : Series
963968
"""
969+
if axis == 1:
970+
data = self[key]
971+
if copy:
972+
data = data.copy()
973+
return data
974+
964975
self._consolidate_inplace()
965976
new_data = self._data.xs(key, axis=1, copy=copy)
966977
if new_data.ndim == 1:

0 commit comments

Comments
 (0)