从R
到{
# In R, create a 'z' column based on values in x and y columns
df <- data.frame(x=rnorm(100),y=rnorm(100))
df$z <- ifelse(df$x > 1.0 | df$y < -1.0, 'outlier', 'normal')
table(df$z)
# output below
normal outlier
66 34
尝试使用Python中的等效语句:
^{pr2}$但是,将引发以下异常:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Python的方法是什么?非常感谢:)
如果要对列执行元素级操作,则不能像这样寻址列。 使用numpy where
试试这个:
相关问题 更多 >
编程相关推荐