I have created this pandas dataframe:
d = {'Char1': [-3,2,0], 'Char2': [0,1,2], 'Char3': [-1,0,-1]}
df = pd.DataFrame(data=d)
print(df)
which looks like this:
I need to create two additional fields:
- Factor1
- Factor2
This is how Factor1 and Factor2 should be populated across each record:
- Factor1 should contain the name of the column with lowest value (again, across each record);
- Factor2 should contain the name of the column with the second lowest value (again, across each record).
So, the resulting dataset should look like this:
So, let's take a look at the first record:
- what is the lowest value? It's -3
- what is the name of the column that that -3 correspond to? It's Char1 -> "Char1" is then assigned to Factor1
- what is the second lowest value? It's -1
- what is the name of the column that that -1 correspond to? It's Char3 -> "Char3" is then assigned to Factor2
And so on.
How can I do this in Python/Pandas?

