【问题标题】:Create a column df[New_column] and write Yes/No based on other multiple column values in pandas创建列 df[New_column] 并根据 pandas 中的其他多列值写入是/否
【发布时间】:2021-10-07 21:29:12
【问题描述】:

申请条件:

我有一个 df,我想根据以下条件填写是/否:

If column1 >= 20 and column2 >= 4 and column3 >= 30 then write Yes else write No 

enter image description here

【问题讨论】:

    标签: python pandas conditional-statements


    【解决方案1】:

    可以使用np.where,如下:

    df['New_column'] = np.where((df['column1'] >= 20) & (df['column2'] >= 4) & (df['column3'] >= 30), 'Yes', 'No')
    

    【讨论】:

      猜你喜欢
      • 2023-01-23
      • 2021-10-05
      • 2021-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多