【发布时间】:2020-11-18 12:22:59
【问题描述】:
我想将列表中的值放入 df 列,条件取决于另一列。我试过了,但它抛出了ValueError:
terms = [0.02, 0.08, 0.24, 0.5, 1, 2]
df['col_1'] = max(list(filter(lambda x: x < df['col_2'], terms)))
col_1 必须包含最接近col_2 的小于它的值。对于0.35,我想输入0.24。
如何在没有循环的情况下实现这一点?
【问题讨论】:
标签: python pandas dataframe filter