I want to add a new column in my data frame. I have a list of events and if any of these is different from 0 the value of the row in the new column should be 1.
I think it should be very simple, but i am fairly new to python.
The dataframe looks like this:
df = pd.DataFrame({"ID":[1,1,2,3],"Date":["01/01/2019","01/01/2019","02/01/2019","02/01/2019"],"Event_1":[1,0,0,0],"Event_2":[1,0,0,1],"Event_3":[0,1,0,1],"Other":[0,0,0,1]})
print(df)
ID Date Event_1 Event_2 Event_3 Other
1 01/01/2019 1 1 0 0
1 01/01/2019 0 0 1 0
2 02/01/2019 0 0 0 0
3 02/01/2019 0 1 1 1
And should look like this:
ID Date Event_1 Event_2 Event_3 Other Conditional_row
1 01/01/2019 1 1 0 0 1
1 01/01/2019 0 0 1 0 1
2 02/01/2019 0 0 0 0 0
3 02/01/2019 0 1 1 1 1
What is the easiest way of doing it? What is the best?