Subsetting dataset by using IF statement

Viewed 33

I have this massive dataset and I need to subset the data by using criteria. This is for illustration:

|      Group         |     Name    |     Value       |
|--------------------|-------------|-----------------|
|          A         |         Bill|            256  |
|          A         |         Jack|            268  |
|          A         |      Melissa|            489  |
|          B         |      Amanda |            787  |
|          B         |         Eric|            485  |
|          C         |         Matt|           1236  |
|          C         |         Lisa|           1485  |
|          D         |         Ben |            785  |
|          D         |       Andrew|           985   |
|          D         |        Cathy|           1025  |
|          D         |      Suzanne|           1256  |
|          D         |          Jim|          1520   |

I know how to handle this problem manually, such as:

    import pandas as pd
    df=pd.read_csv('Test.csv')
    A=df[df.Group =="A "].to_numpy()
    B=df[df.Group =="B "].to_numpy()
    C=df[df.Group =="C "].to_numpy()
    D=df[df.Group =="D "].to_numpy()

But considering the size of the data, it will take a lot of time if I handle it in this way. With that in mind, I would like to know if it is possible to build an iteration with an IF statement that can look at the values in column “Group”(table above) . I was thinking, IF statement to see if the first value is the same with one the below if so, group them and create a new array/ dataframe.

0 Answers
Related