I have data with some sequential features which must come before other feature comes. I would like to get the final page visited by the user.
Setup
import numpy as np
import pandas as pd
df = pd.DataFrame({'user': [10,15,17],
'sex': ['M','M','F'],
'home_page': [1,1,1],
'search_page': [1,0,1],
'confirmation_page': [1,0,0],
'payment_page':[1,0,0]})
print(df)
user sex home_page search_page confirmation_page payment_page
0 10 M 1 1 1 1
1 15 M 1 0 0 0
2 17 F 1 1 0 0
Question
How to get new column with name 'final_page' that have the name of final page visited.
Required answer
df['final_page'] = ['payment_page','home_page','search_page'] # this is not answer,
# The new column should have these values.
my attempt
a = df.iloc[:,2:].to_numpy()
np.trim_zeros(a)