I've asked this question before but the answer I got didn't quite work out as I thought it had, so that here I am.
Previous question: Defining a function for changing column values and creating new datasets
I am trying to define a function where it will take a dataframe and change values in a column to create multiple new dataframes.
As an example, from df1 looking like:
df1:
class colB colC
0 1 1b 1c
1 2 2b 2c
2 3 3b 3c
3 1 4b 4c
4 2 5b 5c
I am trying to create multiple binary classes to implement one-vs-all classification. So the function would create...
df2:
class colB colC
0 1 1b 1c
1 -1 2b 2c
2 -1 3b 3c
3 1 4b 4c
4 -1 5b 5c
df3:
class colB colC
0 -1 1b 1c
1 1 2b 2c
2 -1 3b 3c
3 -1 4b 4c
4 1 5b 5c
df4:
class colB colC
0 -1 1b 1c
1 -1 2b 2c
2 1 3b 3c
3 -1 4b 4c
4 -1 5b 5c
and so on. All the unique values are an incremental value ranging from 1 to 120.
The problem with the previous answer give (np.identity) was that it created dataframes taking every single value as either 1 or -1 instead of categorizing identical values as the same class accordingly.
Thanks
df4? I think only the 2nd row should be1