Python 如何在一定条件下合并第三列中的两列

Python 如何在一定条件下合并第三列中的两列,python,pandas,Python,Pandas,我对熊猫很陌生,我很难解决这个问题: 我有一个医生活动的数据框架 pd0.info() <class 'pa

我对熊猫很陌生,我很难解决这个问题:

我有一个医生活动的数据框架

pd0.info()                                                                                                                                                                                                 
<class 'pandas.core.frame.DataFrame'>
Int64Index: 14059 entries, 0 to 4418
Data columns (total 22 columns):
dossier               14059 non-null object
code_praticien        14059 non-null object
nom_praticien         14059 non-null object
code_anesthesiste     13128 non-null object
nom_anesthesiste      13128 non-null object
patient               14059 non-null object
sexe_patient          14059 non-null object
date_naiss_patient    14059 non-null datetime64[ns]
date                  14059 non-null datetime64[ns]
heure                 13842 non-null float64
ccam_ngap_diag        13852 non-null object
libelle               14059 non-null object
association           7682 non-null float64
modificateur1         11340 non-null object
modificateur2         1262 non-null object
modificateur3         8 non-null float64
modificateur4         0 non-null float64
montant_ccam          13684 non-null float64
montant_ngap          207 non-null float64
depassement           14049 non-null float64
total                 13901 non-null float64
praticien             13128 non-null object
dtypes: datetime64[ns](2), float64(8), object(12)
memory usage: 2.8+ MB
我正在尝试处理外科医生是麻醉师的情况,例如:疼痛控制程序。 在这种情况下,我们有“麻醉师代码”NaN和“麻醉师代码”,这是麻醉师代码之一。 我创建了一个新的列'Anestesiste',当不为空时,该列将包含'code\u Anestesiste'或'code\u Praticin' 当“code\u anesthesiste”为空且“code\u Praticin”为in[有效代码列表\u anesthesiste]时

test['anesthesiste'] = test.code_anesthesiste
test.loc[test.code_anesthesiste.isnull() & test.code_praticien.isin(['MORA01', 'SAVO01'])].anesthesiste = pd0.code_praticien
但我一直遇到这样的错误:ValueError:无法从重复的轴重新编制索引 我在谷歌上搜索了“复制轴”,但不明白我的错误在哪里

我查看了fillna函数,但它似乎不足够,因为我不想在“麻醉师”列中有外科医生的代码,有时外科医生在没有麻醉师的情况下工作,然后我有“麻醉师代码”NaN, 但“行为守则”并不是麻醉师的守则


感谢您的帮助。

您可以在此处使用简单的应用程序:

df=pd.数据帧{'code_practicien':['benyyy00','BENY00','GAUD00','SAVO01'],'code_anasesiste':['MORA01','MORA01',np.NaN,'SAVO01']} df['anethesite']=df.applylambda行:如果pd.isnullrow['code\u Practicesiste']、行['GAUD00','test']中的行['code\u Practicesiste']、行['code\u Practicesiste'],轴=1 df
将['GAUD00','test']替换为您当前的有效麻醉剂列表

请提供一个非常感谢的信息:它解决了我的问题!我将不得不习惯熊猫申请声明!
test['anesthesiste'] = test.code_anesthesiste
test.loc[test.code_anesthesiste.isnull() & test.code_praticien.isin(['MORA01', 'SAVO01'])].anesthesiste = pd0.code_praticien