【问题标题】:Groupby to find min date with conditions in PythonGroupby 在 Python 中查找具有条件的最小日期
【发布时间】:2018-12-21 05:17:39
【问题描述】:

例如,我在数据框中有 3 列

Column_A 有 2 个分类值,例如 A、B

Column_B 也有 3 个分类值,例如 Type1、Type2、Type3

Date 列的值类似于 2010-06-13,2010-06-10

大约有 20,000 行,因此分类列 A、B 的值不断重复。

所以我需要使用 Python(Pandas,Numpy) 找到 Column_A='A' and Column_B='type 1' 的最小日期

【问题讨论】:

    标签: python-3.x pandas numpy jupyter-notebook


    【解决方案1】:

    对loc 和min 使用布尔索引:

    df.loc[(df['Column_A'] == 'A') & (df['Column_B'] == 'type 1'), 'Date'].min()

    【讨论】:

      猜你喜欢
      • 2023-04-07
      • 2018-04-24
      • 2023-02-07
      • 2020-08-29
      • 1970-01-01
      • 2020-10-16
      • 1970-01-01
      • 2017-07-25
      • 2014-09-21
      相关资源
      最近更新 更多