1

I have a DataFrame as below,

    A   B        C      G       R     X6    X8     Class
0   6   860.62  809.73  65.24   573 88.1326 0.2113  A
1   7   871.58  789.74  64.54   849 84.8057 0.2151  A
2   6   854.87  789.74  64.54   687 90.5386 0.2127  B
3   7   823.73  759.75  68.20   475 86.1053 0.2081  B
4   6   823.44  759.75  68.20   424 87.0283 0.2429  B

I want to extract data to new data set of respective class, i.e extract entire class A into one data frame ( 2 entries) & Class B into another data frame ( 3 entries )

I tried using groupby test_new.groupby('Class'), this groups the entire dataset as per class, I would appreciate if someone helped to extract each class using dictionary.

Sid
  • 163
  • 7
  • `df_A = df.query('Class==A').reset_index(drop=True)` and `df_B = df.query('Class==B').reset_index(drop=True)` – James Jan 02 '20 at 08:21
  • I tried this, however I'm unable to get other data for respective class, i.e data under columns A to X8 rows – Sid Jan 02 '20 at 08:26
  • Use `d = dict(tuple(df.groupby('Class')))` – jezrael Jan 02 '20 at 08:33
  • I went through the suggestion question provided, however after spending a while I realised none of the suggestion use dict to solve the query. request jezrael to reopen the query. Also I used the code ```d = dict(tuple(df.groupby('Class')))```, same provides the entire dataset arranged as per the Class, however I need to extract relevant classes respectively, help would really be appreciated – Sid Jan 02 '20 at 09:03

0 Answers0