Skip to content

Commit 83b216c

Browse files
committed
ENH: groupby refactoring, testing, and perf opt. Series, DataFrame take functions
1 parent 558e727 commit 83b216c

File tree

5 files changed

+321
-167
lines changed

5 files changed

+321
-167
lines changed

pandas/core/frame.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ def ix(self):
253253

254254
return self._ix
255255

256+
@property
257+
def shape(self):
258+
return (len(self.index), len(self.columns))
259+
256260
#----------------------------------------------------------------------
257261
# Class behavior
258262

@@ -997,6 +1001,34 @@ def reindex_like(self, other, method=None):
9971001
return self.reindex(index=other.index, columns=other.columns,
9981002
method=method)
9991003

1004+
def take(self, indices, axis=0):
1005+
"""
1006+
Analogous to ndarray.take, return DataFrame corresponding to requested
1007+
indices along an axis
1008+
1009+
Parameters
1010+
----------
1011+
indices : list / array of ints
1012+
axis : {0, 1}
1013+
1014+
Returns
1015+
-------
1016+
taken : DataFrame
1017+
"""
1018+
if axis == 0:
1019+
new_index = self.index.take(indices)
1020+
new_columns = self.columns
1021+
else:
1022+
new_index = self.index
1023+
new_columns = self.columns.take(indices)
1024+
1025+
# TODO: implement take on BlockManager
1026+
if self._data.is_mixed_dtype():
1027+
return self.reindex(index=new_index, columns=new_columns)
1028+
1029+
new_values = self.values.take(indices, axis=axis)
1030+
return DataFrame(new_values, index=new_index, columns=new_columns)
1031+
10001032
#----------------------------------------------------------------------
10011033
# Reindex-based selection methods
10021034

0 commit comments

Comments
 (0)