![](/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.