Blue
Blue

Reputation: 191

Min Values in each row of selected columns in Python

Hi I have a rather simple task but seems like all online help is not working. I have data set like this:

ID   |  Px_1       | Px_2
theta|  106.013676 | 102.8024788702673
Rho  |  100.002818 | 102.62640389123405
gamma|  105.360589 | 107.21999706084836
Beta |  106.133046 | 115.40449479551263
alpha|  106.821119 | 110.54312246081719

I want to find min by each row in a fourth col so the output I can have is for example, theta is 102.802 because it is the min value of both Px_1 and Px_2

I tried this but doesnt work I constantly get max value

df_subset = read.set_index('ID')[['Px_1','Px_2']]
d = df_subset.min( axis=1) 

Thanks

Upvotes: 0

Views: 75

Answers (1)

Tai
Tai

Reputation: 8004

You can try this

df["min"] = df[["Px_1", "Px_2"]].min(axis=1)

Select the columns needed, here ["Px_1", "Px_2"], to perform min operation.

Upvotes: 2

Related Questions