I came across a function called quantile()
in pandas. Can somebody help me explain how this function works and what it does? An example will be extremely appreciated.
I am writing a sample code to help you better understand this function
Code i have so far:
def get_quantile_based_buckets(feature_values, num_buckets):
quantiles = feature_values.quantile([(i+1.)/(num_buckets+1.) for i in list(range(num_buckets))])
print(quantiles)
return [quantiles[q] for q in quantiles.keys()]
here feature_values
is a pandas DataFrame()
.
Here is an example to explain this function:
>>> df = pd.DataFrame(np.array([[1, 1], [2, 10], [3, 100], [4, 100]]),
columns=['a', 'b'])
>>> df.quantile(.1)
a 1.3
b 3.7
dtype: float64
>>> df.quantile([.1, .5])
a b
0.1 1.3 3.7
0.5 2.5 55.0
If someone could explain the above example, that would be great. For more info and question clarity please specify in the comment section.