Python 引用其他列值的IF语句
我一辈子都找不到熊猫这种手术的例子。。。。我试图写一个IF语句,说明如果我的Check列为true,那么从我的experience\u value列中提取值,如果为False,那么默认值为1000Python 引用其他列值的IF语句,python,pandas,Python,Pandas,我一辈子都找不到熊猫这种手术的例子。。。。我试图写一个IF语句,说明如果我的Check列为true,那么从我的experience\u value列中提取值,如果为False,那么默认值为1000 report_skills['Check'] = report_skills.apply(lambda x: x.Skill_Specialization in x.Specialization, axis=1) report_skills = report_skills.loc[report_ski
report_skills['Check'] = report_skills.apply(lambda x: x.Skill_Specialization in x.Specialization, axis=1)
report_skills = report_skills.loc[report_skills['Check'] == True, 'Proficiency_Value'] = 1000
你知道为什么这不起作用吗?我相信这是一个简单的解决方案让我们创建一个小示例数据框,如下所示:
import pandas as pd
import numpy as np
df = pd.DataFrame({'Check':[True,False, False ,True],
'Proficiency_Value':range(4)
})
>>> df
Check Proficiency_Value
0 True 0
1 False 1
2 False 2
3 True 3
如果您现在使用np.where()
函数E,您可以得到您想要的结果
df['Proficiency_Value'] = np.where(df['Check']==True, df['Proficiency_Value'], 1000)
>>> df
Check Proficiency_Value
0 True 0
1 False 1000
2 False 1000
3 True 3
np.where(report\u skills['Check']==True,report\u skills['Proficiency\u Value'],1000)
?以后,您可以参考此链接。。。