根据来自A,B两列的数据(值:'a','b','c','d','e')创建列C(值:0,1):如果在A或B中,值' a',则C = 1,其余C = 0

时间:2019-05-04 19:21:37

标签: python pandas calculated-columns

A的DataFrame有4列,并带有不同的CIE-09代码。如果每列中的任何代码与我指定的代码一致,则新列将采用值1,否则,新列将采用值0。

 x_coord <- c(16.48438,  17.49512,  24.74609, 22.59277, 16.48438)
 y_coord <- c(59.736328125, 55.1220703125, 55.0341796875, 
 61.142578125, 59.736328125)
 xym <- cbind(x_coord, y_coord)
 xym

 library(sp)
 p = Polygon(xym)
 ps = Polygons(list(p),1)
 sps1 = SpatialPolygons(list(ps))
 plot(sps1)
column A
491.21
042
NaN
NaN

column B
042, 
304.90,
305.1,
711.02,

Column C
711,
304.01,
304.93,
573.3,

如果列A,B或C的值为'042',则列D = 1;否则,列D = 0。

所以D列应该是:

NEw column D: 
Values (0,1)

0 个答案:

没有答案