Create a dataframe from another df which selected only those columns having min value of each row excluding 0 as min and exclude operation on few rows

Solution 1:

Use:

#convert string column 
df1 = In.set_index('A').replace(0, np.nan)
#get all minimal per columns, rows
m1 = df1.eq(df1.min(axis=1), axis=0)
m2 = df1.eq(df1.min())
#filtering
df = df1.loc[m2.any(axis=1), m1.any()].reset_index()
print (df)
   A     B   D
0  V  13.0  45
1  W  13.0  45
2  X   NaN  12
3  Y  12.0  56

Solution 2:

I don't understand the logic between remove V and Z but you can try:

Out = In.set_index('A').drop(['V', 'Z']).replace(0, np.nan) \
        .loc[:, lambda x: x.idxmin(1).unique()].reset_index()
print(Out)

# Output
   A     B   D
0  W  13.0  45
1  X   NaN  12
2  Y  12.0  56