Skip to content
Advertisement

Minimum value for each row in pandas dataframe

im trying to compute the minimum for each row in a pandas dataframe.

I would like to add a column that calculates the minimum values and ignores “NaN” and “WD”

For example

JavaScript

should give me a new column like

JavaScript

I tried df.where(df > 0).min(axis=1) and df.where(df != "NaN").min(axis=1) without success

Advertisement

Answer

Convert values to numeric with non numeric to NaNs by errors='coerce' in to_numeric and DataFrame.apply so is possible use min:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement