python - Pandas if/then/else logic -
i have dataframe looks this,
df=pd.dataframe([2,4,6,2],columns=['x']) df['y']=[3,2,1,2] df['x_test']=['x_larger','x_larger','x_smaller','x_equal']
i trying if/then/else, similar idiom , cookbook. able 1 if statement correct not sure how test equal.
df['valid']=false df['invalid']=true df.ix[(df.x_test=="x_larger") & (df.x>df.y),['valid','invalid']]=[true,false]
this works partially. test x_equal in line. possible?
the desired output should be
x y x_test valid invalid 0 2 3 x_larger false true 1 4 2 x_larger true false 2 6 1 x_smaller false true 3 2 2 x_equal true false
Comments
Post a Comment