![](/img/trans.png)
[英]Python/Pandas - How to group by two columns and count rows with value from third column between two numbers
[英]How to select pandas row with maximum value in one column, from a group of rows that share two common columns?
If not last 2 columns has same values use numpy.isclose
for select columns by some precision, also for performance is better select by DataFrame.loc
by mask and column name:
df.loc[np.isclose(df['col4'], 0.999141) & np.isclose(df['col5'], 0.000861559), 'col3'].max()
对于最大值使用Series.idxmax
的索引:
df.loc[np.isclose(df['col4'], 0.999141) & np.isclose(df['col5'], 0.000861559), 'col3'].idxmax()
对于 select 通过最大col4
和最小col5
使用:
df.loc[df['col4'].eq(df['col4'].max()) & df['col5'].eq(df['col5'].min()), 'col3'].max()
df.loc[df['col4'].eq(df['col4'].max()) & df['col5'].eq(df['col5'].min()), 'col3'].idxmax()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.