Skip to content Skip to sidebar Skip to footer

Pandas Return Column Name Apply Function For Each Row

I am working on the pandas dataset. For 2D dataframe try to return/append one column which return the column name whose value is over 0.95. import pandas as pd import numpy as np

Solution 1:

Use pd.DataFrame.idxmax

df.assign(Column=df.gt(.95).assign(zip5=1).idxmax(1))

   EXP_DAY_1  EXP_DAY_2  EXP_DAY_3  EXP_DAY_4  EXP_DAY_5  EXP_DAY_6  EXP_DAY_7  EXP_DAY_8  EXP_DAY_9  EXP_DAY_10  EXP_GT_DAY_10     Column
0        0.0        0.0       0.52       0.94       0.94        1.0        1.0        1.0        1.0         1.0            0.0  EXP_DAY_6
1        0.0        0.0       0.00       0.66       1.00        1.0        1.0        1.0        1.0         1.0            0.0  EXP_DAY_5
2        0.0        1.0       1.00       1.00       1.00        1.0        1.0        1.0        1.0         1.0            0.0  EXP_DAY_2
3        0.0        0.0       0.92       1.00       1.00        1.0        1.0        1.0        1.0         1.0            0.0  EXP_DAY_4
4        0.0        0.0       0.95       0.97       1.00        1.0        1.0        1.0        1.0         1.0            0.0  EXP_DAY_4

Post a Comment for "Pandas Return Column Name Apply Function For Each Row"