## Grouping numerical values in categories

how to categorize age groups in r
categorize data by range of values in r
how to categorize data in r
matlab group data by value
grouping variable examples
category in r
group numeric variables in r
cut function in r

I have numeric data within Student marks and I would like to group them into 3 categories A, B and C.

```df = pd.DataFrame([('Adel',  3.5),
('Betty',  2.75),
('Djamel',  2.10),
('Ramzi',  1.75),
('Alexa', 3.15)],
columns=('Name', 'GPA'))
```

I tried function `pd.cut()` but it didn't lead to wanted result .

Here's a way using `pd.cut`:

```df = df.sort_values('GPA')

df['bins'] = pd.cut(df['GPA'], bins=3, labels = ['A','B','C'])

Name   GPA bins
3   Ramzi  1.75    A
2  Djamel  2.10    A
1   Betty  2.75    B
4   Alexa  3.15    C
```

R Handbook: Converting Numeric Data to Categories, Clear examples in R. Categorizing data; Percentiles; Clustering, PAM, Medoids. One approach is to create categories according to logical cut-off values in the� Select any cells in the row labels that have the sales value. Go to Analyze –> Group –> Group Selection. In the grouping dialog box, specify the Starting at, Ending at, and By values. In this case, By value is 250, which would create groups with an interval of 250. Click OK.

In a recent research, a PSO was implemented to classify students under unknown number of groups. PSO showed improved capabilities compared to GA. I think that all you need is the specific research.

The paper is: Forming automatic groups of learners using particle swarm optimization for applications of differentiated instruction

You can find the paper here: https://doi.org/10.1002/cae.22191

Perhaps the researchers could guide you through researchgate: https://www.researchgate.net/publication/338078753

You just need to remove the technic from automatic number of groups

Grouping data and assigning alphabet and numeric values for new , Every time a new combination of values appear in the concatenated values (col 4 ) for a particular group (col2), I need to assign a new category for that row both� One approach is to create categories according to logical cut-off values in the scores or measured values. An example of this is the common grading system in the U.S. in which a 90% grade or better is an “A”, 80–89% is “B”, etc. It is common in this approach to make the categories with equal spread in values.

I found this solution :

```import pandas as pd, numpy as np

df = pd.DataFrame({'GPA': [99, 53, 71, 84, 84],
'Name': ['Betty', 'Djamel', 'Ramzi', 'Alexa', 'Adel']})

bins = [0, 50, 60, 70, 80, 100]
names = ['F', 'D', 'C', 'B', "A"]

d = dict(enumerate(names, 1))

df['Rank'] = np.vectorize(d.get)(np.digitize(df['GPA'], bins))

```