Skip to content

added describe and scoreatpercentile in frame.py #37

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

Merged
merged 1 commit into from Mar 18, 2011
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,30 @@ def _union_index(self, other):

return union_index

def describe(self):
"""
Generate various summary statistics of columns, excluding NaN values

Returns
-------
DataFrame
"""
cols = self._get_numeric_columns()

tmp = self.reindex(columns=cols)

cols_destat = ['count', 'mean', 'std', 'min', '10%', '50%', '90%', 'max']

list_destat = [tmp.count(), tmp.mean(), tmp.std(), tmp.min(),
tmp.scoreatpercentile(10), tmp.median(), tmp.scoreatpercentile(90), tmp.max()]

destats = self._constructor(np.zeros((len(cols), len(cols_destat))), index=cols, columns=cols_destat)

for i, k in enumerate(list_destat):
destats[cols_destat[i]] = k

return destats

def dropEmptyRows(self, specificColumns=None):
"""
Return DataFrame with rows omitted containing ALL NaN values
Expand Down Expand Up @@ -2097,6 +2121,38 @@ def mean(self, axis=0):

return summed / count

def scoreatpercentile(self, per=50, axis=0):
"""
Return array or Series of score at the given `per` percentile
over requested axis.

Parameters
----------
per : percentile

axis : {0, 1}
0 for row-wise, 1 for column-wise

Returns
-------
Series or TimeSeries
"""
from scipy.stats import scoreatpercentile

def f(arr, per):
if arr.dtype != np.float_:
arr = arr.astype(float)
return scoreatpercentile(arr[notnull(arr)], per)

if axis == 0:
scoreatper = [f(self[col].values, per) for col in self.columns]
return Series(scoreatper, index=self.columns)
elif axis == 1:
scoreatper = [f(self.xs(k).values, per) for k in self.index]
return Series(scoreatper, index=self.index)
else:
raise Exception('Must have 0<= axis <= 1')

def median(self, axis=0):
"""
Return array or Series of medians over requested axis.
Expand Down