📌  相关文章
📜  如果值高于某个值,pandas 添加标志 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:52.315000             🧑  作者: Mango

代码示例1
# np.where function works as follows:
import numpy as np

# E.g. 1 - Set column values based on if another column is greater than or equal to 50
df['X'] = np.where(df['Y'] >= 50, 'yes', 'no')

# E.g. 2 - Replace values over 20000 with 0, otherwise keep original value
df['my_value'] = np.where(df.my_value > 20000, 0, df.my_value)