[英]change cell value based on condition
username status debt
John pending $1000
Mike pending $0
Daymond cleared $0
How can I change the status of pending to cleared if the status is pending and debt is 0?如果状态为待处理且债务为 0,如何将待处理状态更改为已清除?
You can use您可以使用
m = df['status'].eq('pending') & df['debt'].eq('$0')
df.loc[m, 'status'] = 'cleared'
# or
df['status'] = df['status'].mask(m, 'cleared')
# or
df['status'] = np.where(m, 'cleared', df['status'])
print(df)
username status debt
0 John pending $1000
1 Mike cleared $0
2 Daymond cleared $0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.