Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 引用其他列值的IF语句_Python_Pandas - Fatal编程技术网

Python 引用其他列值的IF语句

Python 引用其他列值的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

我一辈子都找不到熊猫这种手术的例子。。。。我试图写一个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_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)
?以后,您可以参考此链接。。。