[英]Union of two variables to form a new one in Pandas Data Frame - Python
I have a data frame , and I want to create a new data frame based on the values of two columns. 我有一个数据框,我想基于两列的值创建一个新的数据框。 The pair of values alwyas would be:
'x' and 'x'
or 'x' and NaN
or NaN and 'x'
or NaN and NaN
. 该对值alwyas将是:
'x' and 'x'
或'x' and NaN
或NaN and 'x'
或NaN and NaN
。 So for the first three examples the values of the new varabiel would b 'x'
and for the last one would be NaN
. 因此,对于前三个示例,新varabiel的值将为b'x
'x'
,对于最后一个示例将为NaN
。 Nan is missing value. Nan缺少价值。
The pandas data frame is: 熊猫数据框是:
Name Company nameC.antiguo Company nameC.completado
ssd X X
adf B NaN
dsf C C
eee NaN NaN
wqe NaN C
I tried the following code but it doen´t work at all. 我尝试了以下代码,但是根本不起作用。
pruebaofempat['bn']= pruebaofempat['Company nameC.antiguo'] + pruebaofempat['Company nameC.completado']
So, How Can I create the new variable correctly? 那么,如何正确创建新变量?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.