Quantcast
Channel: Data Science, Analytics and Big Data discussions - Latest topics
Viewing all articles
Browse latest Browse all 4448

Creating a new variable with multiple conditions in python

$
0
0

@syed.danish wrote:

Hi,
I am trying to create a new variable in a data frame by applying conditions on two other variable but it is giving me errorm, similar approach would have worked on R :
train['day_type']=''
train.day_type[(train['holiday']==1 & train['workingday']==0)]='holiday'

it is giving me the following error :

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

but when i try to use the above code by applying the condition on only one variable it works :
train['day_type']=''
train.day_type[(train['holiday']==1 )]='holiday'

P.S. its working just fine with only one comparison using (.ix )or not but when i try to use two comparison by using and ,or it gives out error.

please help !!

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4448

Trending Articles