1

I have a dataframe like this one below:

import pandas as pd
df1 = pd.DataFrame({"ID":["001","002","003","007","009"],
                   "A":[4, 6, 1, 2, 6],
                   "B":[1, 7, 2, 3, 9]})

    ID  A  B
0  001  4  1
1  002  6  7
2  003  1  2
3  007  2  3
4  009  6  9

I need to create a new one (df2) with three columns (ID, CLASS, NUMBERS) based on the information from the last one. Basically, df2 should convert the columns A and B from df1 into a new column in df2, while relating this info to the ID column. The ID values would be repeated by the number of classes (A and B)

The result should be something like this:

enter image description here

I can't figure out the logic to do that. Could anyone help me with this code?

user026
  • 638
  • 4
  • 14

0 Answers0