I would like to check if a certain column has a certain value in a row. If so, a new column should be created with a value.
I have solved this problem too. Unfortunately my code is very slow. Does anyone have an idea how I could solve this to make it go faster? There must be a more elegant solution.
temp = []
for index, row in df_event.iterrows():
if row['event'] == ("view"):
temp.append(1)
if row['event'] == ("addtocart"):
temp.append(2)
if row['event'] == ("transaction"):
temp.append(3)
df['event'] = temp
df['event'].head()
This is my dataframe and what I want
Each event should get a code. View =1, addtocart = 2, transaction = 3
How could I replace my code with a map
function?