计算 Pandas DataFrame 中每一行的最小值

Computing the minimum value for each row in a Pandas DataFrame

我有这个 DataFrame df:

A   B   C   D
1   3   2   1
3   4   1   2
4   6   3   2
5   4   5   6

我想添加一个计算最小值的列,通过对列A到D进行切片(实际df更大,所以我需要对它进行切片)即

Dmin
1
1
2
4

我可以按如下方式计算 1 行的最小值

df.iloc[0].loc['A':'D'].min()

我为整个 DataFrame 尝试了以下操作,所有这些都给出了 NaN

df['Dmin']=df.loc[:,'A':'D'].min()

df['Dmin']=df.iloc[:].loc['A':'D'].min()

df['Dmin']=df.loc['A':'D'].min()

pandas.DataFrame.minaxis=1 一起使用:

df['Dmin'] = df.min(axis=1)