I have the following dataframe:
data = [
(27450, 27450, 29420,"10/10/2016"),
(29420 , 36142, 29420, "10/10/2016"),
(11 , 11, 27450, "10/10/2016")]
#Create DataFrame base
df = pd.DataFrame(data, columns=("User_id","Actor1","Actor2", "Time"))
The first column contains the user_id, and each line represents one action that he makes. Each user_id shows up either in "Actor1" or "Actor2" column.
First, I would like to create a new column where it will assign the value 1 if the user_id is found in "Actor1" column and 0 otherwise.
Second, I would like to create a new column where for each user_id it will store the "Actor"_i value that he interacted with.
For the above example, the output will look like:
Col1 Col2
1 29420
0 36142
1 27450
What is the most efficient pythonic way to do this?
Thanks a lot in advance!