Create a dummy variable from if any value from multiple column is over a certain value

时间:2019-04-16 22:57:09

标签: python-3.x pandas dummy-variable

I want to create a new dummy variable if the any of the three colunm exceeds a certain value.

df = pd.DataFrame({'id':[1,2,3,4,5,6],'amount_1':[1,8,9,1,10,12],'amount_2':[2,9,6,5,2,1],'amount_3':[2,5,1,5,5,7]})
print(df)

I want a dummy variable if any value in colunm amount_1, amount_2 or amount_3 is greater than 5

df = {'id':[1,2,3,4,5,6],'amount_1':[1,2,1,1,10,2],amount_2:[2,9,6,5,2,1],'amount_3':[2,5,1,5,5,3],'dummy':[0,1,1,0,1,0]}
print(df)

0 个答案:

没有答案