@@ -1036,20 +1036,16 @@ def describe(self):
1036
1036
DataFrame
1037
1037
"""
1038
1038
cols = self ._get_numeric_columns ()
1039
-
1040
1039
tmp = self .reindex (columns = cols )
1041
1040
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' ]
1048
1043
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 ()]
1051
1047
1052
- return destats
1048
+ return self . _constructor ( data , index = cols_destat , columns = cols )
1053
1049
1054
1050
def dropEmptyRows (self , specificColumns = None ):
1055
1051
"""
@@ -2156,37 +2152,33 @@ def mean(self, axis=0):
2156
2152
2157
2153
return summed / count
2158
2154
2159
- def scoreatpercentile (self , per = 50 , axis = 0 ):
2155
+ def quantile (self , q = 0.5 , axis = 0 ):
2160
2156
"""
2161
2157
Return array or Series of score at the given `per` percentile
2162
2158
over requested axis.
2163
2159
2164
2160
Parameters
2165
2161
----------
2166
- per : percentile
2162
+ q : quantile
2163
+ 0 <= q <= 1
2167
2164
2168
2165
axis : {0, 1}
2169
2166
0 for row-wise, 1 for column-wise
2170
2167
2171
2168
Returns
2172
2169
-------
2173
- Series or TimeSeries
2170
+ quantiles : Series
2174
2171
"""
2175
2172
from scipy .stats import scoreatpercentile
2176
2173
2177
- def f (arr , per ):
2174
+ per = q * 100
2175
+
2176
+ def f (arr ):
2178
2177
if arr .dtype != np .float_ :
2179
2178
arr = arr .astype (float )
2180
2179
return scoreatpercentile (arr [notnull (arr )], per )
2181
2180
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 )
2190
2182
2191
2183
def median (self , axis = 0 ):
2192
2184
"""
0 commit comments