[英]Return the maximum value of two columns in a dataframe (Pandas)
I currently have a dataframe and would like to return the minimum value of two columns (eg. X and Y). 我目前有一个数据帧,并希望返回两列的最小值(例如X和Y)。
I have tried: 我努力了:
print(df.loc[:, ['X', 'Y']].min())
However, it prints out: 但它打印出来:
Control NSAF -9.851210
Wild NSAF -9.730507
dtype: float64
Whereas I just want -9.851210. 而我只想要-9.851210。 Is there a way to just get the single minimum number? 有没有办法获得单个最小数量?
Thank you 谢谢
再加一min
print(df.loc[:, ['X', 'Y']].min().min())
The below given example may be useful for you to find 以下给出的示例可能对您有用
maximum and minimum of "X" and "Y" columns “X”和“Y”列的最大值和最小值
df[["X", "Y"]].max(axis=1)
df[["X", "Y"]].min(axis=1)
use the numpy min
method on the underlying values
attribute 在基础values
属性上使用numpy min
方法
df.loc[:, ['X', 'Y']].values.min()
You can even find the locations of 'X'
and 'Y'
ahead of time 您甚至可以提前找到'X'
和'Y'
的位置
j = [df.columns.get_loc(c) for c in ['X', 'Y']]
df.values[:, j].min()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.