dataframe - 如何根据条件替换列中的值
问题描述
数据集:
cust no acc no schme code product code
0 102283447 809002316863 swmse rbl finserve
1 102283447 809002661291 ecltl ecl
2 101124069 809001215907 aksme akshada
3 101124069 809001211305 aksme akshada
4 101124069 8090012837146 ecltl ecl
import pandas as pd
import numpy as np
if ((data['cust no'].duplicated()==True).any() and (data['product code']!='rbl finserve').any()):
data['new']=='other bc acc'
else:
data['new']==data['schme code']
data['new']=np.nan
for i in data['product code']:
if i!='rbl finserve':
if (data['schme code']=='ecltl').any():
data['new']=='other ecl bc'
else:
data['new']=data['schme code']
如果帐户超过两个,我想更改 schme 代码。对于那些将第一个帐户产品作为 rbl finserve 的帐户,则不要更改,但如果不是“rbl finserve”,则将 schme 代码从“ecltl”更改为“其他 ecltl bc”
解决方案
cust no acc no schme code product code
0 102283447 809002316863 swmse rbl finserve
1 102283447 809002661291 ecltl ecl
2 101124069 809001215907 aksme akshada
3 101124069 809001211305 aksme akshada
4 101124069 8090012837146 ecltl ecl
推荐阅读
- python - 想使用 selenium-wedriver 从站点中提取数据
- .net - .net framework 4.8 和 dotnet 5 之间的 WebRequest 行为不同
- postgresql - PostgreSQL:布尔列验证条件是否为真
- javascript - 在按钮单击 javascript 上发生 2 个操作
- azure-ad-b2c - 如何向 Azure B2C REST 调用添加其他标头信息?
- javascript - 带有异常的 Javascript substr
- r - ggplot2中的半正态图残差图
- javascript - 使用 forEach 和 map 进行迭代时,数组值会发生突变
- javascript - 在javascript中使用对象默认值初始化一个数组
- powerbi - Power BI:报告发布后切片器不起作用