gpt4 book ai didi

python - 根据值过滤 pandas DataFrame 中的行

转载 作者:太空宇宙 更新时间:2023-11-04 08:46:14 25 4
gpt4 key购买 nike

我有类似于下面的 DataFrame(这只是一个示例):

i   TIME    CITIES_LABEL    Value   lat_rounded long

2 2005 Tilburg 22 250 52.070498 4.300700
3 2005 Amsterdam 45 825 52.370216 4.895168
4 2005 Rotterdam 27 600 51.924420 4.477733
5 2005 Utrecht 12 915 52.090737 5.121420
6 2005 Eindhoven 9 165 51.441642 5.469722
7 2006 Tilburg 7 800 51.560596 5.091914
8 2005 Groningen 7 620 53.219383 6.566502
9 2005 Enschede 6 250 52.221537 6.893662
10 2005 Arnhem 6 025 51.985103 5.898730
11 2006 Utrecht 3 400 50.888174 5.979499
12 2006 Amsterdam 6 795 52.350785 5.264702
13 2005 Breda 8 565 51.571915 4.768323
14 2010 Groningen 6 325 51.812563 5.837226
15 2005 Apeldoorn 7 005 52.211157 5.969923
16 2007 Utrecht 3 785 53.201233 5.799913
17 2006 Rotterdam 7 130 52.387388 4.646219
18 2005 Zaanstad 6 060 52.457966 4.751042
19 2008 Tilburg 6 945 51.697816 5.303675
20 2007 Amsterdam 5 840 52.156111 5.387827
21 2005 Maastricht 5 220 50.851368 5.690972

城市沿 CITIES_LABEL 字段重复。我想根据最高 TIME 值过滤城市。我想要的输出示例是:

i   TIME    CITIES_LABEL    Value   lat_rounded long

6 2005 Eindhoven 9 165 51.441642 5.469722
9 2005 Enschede 6 250 52.221537 6.893662
10 2005 Arnhem 6 025 51.985103 5.898730
13 2005 Breda 8 565 51.571915 4.768323
14 2010 Groningen 6 325 51.812563 5.837226
15 2005 Apeldoorn 7 005 52.211157 5.969923
16 2007 Utrecht 3 785 53.201233 5.799913
17 2006 Rotterdam 7 130 52.387388 4.646219
18 2005 Zaanstad 6 060 52.457966 4.751042
19 2008 Tilburg 6 945 51.697816 5.303675
20 2007 Amsterdam 5 840 52.156111 5.387827
21 2005 Maastricht 5 220 50.851368 5.690972

关于如何最好地在 pandas 中解决这个问题有什么想法吗?

编辑

我的问题不同于Python : How can I get Rows which have the max value of the group to which they belong?因为我正在为 TIMECITIES_LABEL 寻找过滤器,而上一个问题只是查看基于一个字段的(最大)值的过滤,而它没有注意其他领域的重复

最佳答案

使用groupbyidxmax

df.ix[df.groupby('CITIES_LABEL').TIME.idxmax()]

enter image description here

关于python - 根据值过滤 pandas DataFrame 中的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40289914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com