Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement Percentile groups with python

Shulou Source: shulou.com Published: 2022-06-01 04:51:07 10月03日 Update

Editor to share with you how python to achieve Percentile groups, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Percentile groups

You have a number column, and you want to classify the values in this column into groups, for example, the first 5% of the column is divided into group 1, the first 5-20% is divided into group 2, the first 20% of 50% is divided into group 3, and the last 50% is divided into group 4. Of course, you can do it with pandas.cut, but here's another option:

Import numpy as np cut_points = [np.percentile (df ['c'], I) for i in [50,80,95]] df ['group'] = 1 for i in range (3): df [' group'] = df ['group'] + (df [' c'] < cut_ points [I]) # or

Tags: Articles content not much functions most instructions numbers more knowledge industry computers information channels channels classification reference learning help application run Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Microsoft Apple Docker vpn