@@ -1162,7 +1162,7 @@ def replace(self, to_replace, value, subset=None):
11621162 self ._jdf .na ().replace (self ._jseq (subset ), self ._jmap (rep_dict )), self .sql_ctx )
11631163
11641164 @since (2.0 )
1165- def approxQuantile (self , col , probabilities , relativeError ):
1165+ def approxQuantile (self , cols , probabilities , relativeError ):
11661166 """
11671167 Calculates the approximate quantiles of a numerical column of a
11681168 DataFrame.
@@ -1181,7 +1181,7 @@ def approxQuantile(self, col, probabilities, relativeError):
11811181 Space-efficient Online Computation of Quantile Summaries]]
11821182 by Greenwald and Khanna.
11831183
1184- :param col : the name of the numerical column
1184+ :param cols : the name(s) of the numerical column(s)
11851185 :param probabilities: a list of quantile probabilities
11861186 Each number must belong to [0, 1].
11871187 For example 0 is the minimum, 0.5 is the median, 1 is the maximum.
@@ -1191,8 +1191,13 @@ def approxQuantile(self, col, probabilities, relativeError):
11911191 accepted but give the same result as 1.
11921192 :return: the approximate quantiles at the given probabilities
11931193 """
1194- if not isinstance (col , str ):
1195- raise ValueError ("col should be a string." )
1194+ if not isinstance (cols , (str , list , tuple )):
1195+ raise ValueError ("col should be a string, list or tuple." )
1196+
1197+ if isinstance (cols , tuple ):
1198+ cols = list (cols )
1199+ if isinstance (cols , list ):
1200+ cols = _to_list (self ._sc , cols )
11961201
11971202 if not isinstance (probabilities , (list , tuple )):
11981203 raise ValueError ("probabilities should be a list or tuple" )
@@ -1207,8 +1212,12 @@ def approxQuantile(self, col, probabilities, relativeError):
12071212 raise ValueError ("relativeError should be numerical (float, int, long) >= 0." )
12081213 relativeError = float (relativeError )
12091214
1210- jaq = self ._jdf .stat ().approxQuantile (col , probabilities , relativeError )
1211- return list (jaq )
1215+ jaq = self ._jdf .stat ().approxQuantile (cols , probabilities , relativeError )
1216+ jaq = list (jaq )
1217+ for idx , a in enumerate (jaq ):
1218+ if not isinstance (a , (list , float )):
1219+ jaq [idx ] = list (a )
1220+ return jaq
12121221
12131222 @since (1.4 )
12141223 def corr (self , col1 , col2 , method = None ):
@@ -1440,8 +1449,8 @@ class DataFrameStatFunctions(object):
14401449 def __init__ (self , df ):
14411450 self .df = df
14421451
1443- def approxQuantile (self , col , probabilities , relativeError ):
1444- return self .df .approxQuantile (col , probabilities , relativeError )
1452+ def approxQuantile (self , cols , probabilities , relativeError ):
1453+ return self .df .approxQuantile (cols , probabilities , relativeError )
14451454
14461455 approxQuantile .__doc__ = DataFrame .approxQuantile .__doc__
14471456
0 commit comments