Skip to content

Commit ffc49d7

Browse files
committed
tweaked describe and renamed scoreatpercentile to quantile
1 parent 9ef6253 commit ffc49d7

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

pandas/core/frame.py

+14-22
Original file line numberDiff line numberDiff line change
@@ -1036,20 +1036,16 @@ def describe(self):
10361036
DataFrame
10371037
"""
10381038
cols = self._get_numeric_columns()
1039-
10401039
tmp = self.reindex(columns=cols)
10411040

1042-
cols_destat = ['count', 'mean', 'std', 'min', '10%', '50%', '90%', 'max']
1043-
1044-
list_destat = [tmp.count(), tmp.mean(), tmp.std(), tmp.min(),
1045-
tmp.scoreatpercentile(10), tmp.median(), tmp.scoreatpercentile(90), tmp.max()]
1046-
1047-
destats = self._constructor(np.zeros((len(cols), len(cols_destat))), index=cols, columns=cols_destat)
1041+
cols_destat = ['count', 'mean', 'std', 'min',
1042+
'10%', '50%', '90%', 'max']
10481043

1049-
for i, k in enumerate(list_destat):
1050-
destats[cols_destat[i]] = k
1044+
data = [tmp.count(), tmp.mean(), tmp.std(), tmp.min(),
1045+
tmp.quantile(.1), tmp.median(),
1046+
tmp.quantile(.9), tmp.max()]
10511047

1052-
return destats
1048+
return self._constructor(data, index=cols_destat, columns=cols)
10531049

10541050
def dropEmptyRows(self, specificColumns=None):
10551051
"""
@@ -2156,37 +2152,33 @@ def mean(self, axis=0):
21562152

21572153
return summed / count
21582154

2159-
def scoreatpercentile(self, per=50, axis=0):
2155+
def quantile(self, q=0.5, axis=0):
21602156
"""
21612157
Return array or Series of score at the given `per` percentile
21622158
over requested axis.
21632159
21642160
Parameters
21652161
----------
2166-
per : percentile
2162+
q : quantile
2163+
0 <= q <= 1
21672164
21682165
axis : {0, 1}
21692166
0 for row-wise, 1 for column-wise
21702167
21712168
Returns
21722169
-------
2173-
Series or TimeSeries
2170+
quantiles : Series
21742171
"""
21752172
from scipy.stats import scoreatpercentile
21762173

2177-
def f(arr, per):
2174+
per = q * 100
2175+
2176+
def f(arr):
21782177
if arr.dtype != np.float_:
21792178
arr = arr.astype(float)
21802179
return scoreatpercentile(arr[notnull(arr)], per)
21812180

2182-
if axis == 0:
2183-
scoreatper = [f(self[col].values, per) for col in self.columns]
2184-
return Series(scoreatper, index=self.columns)
2185-
elif axis == 1:
2186-
scoreatper = [f(self.xs(k).values, per) for k in self.index]
2187-
return Series(scoreatper, index=self.index)
2188-
else:
2189-
raise Exception('Must have 0<= axis <= 1')
2181+
return self.apply(f, axis=axis)
21902182

21912183
def median(self, axis=0):
21922184
"""

0 commit comments

Comments
 (0)