Generation

generate functionFri, 27 Jan 2023

There is a Pandas dataframe user_id name date hotel profit_per_room how_find_us resting_time rating 0 1 Ksenia Rodionova 2021-07-01 Alpina 1639.000000 by_recommendation 48 3.0 1 2 Ulyana Selezneva 2021-07-01 AquaMania 930.000000 by_airbnb.com 97 4.0 2 3 Konstantin Prokhorov 2021-07-01 Breeze 1057.720000 agg_trivago.com 173 4.0 3 4 Petrov Vladimir 2021-07-01 Moreon 1403.000000 agg_onlinetours.ru 229 4.0 4 5 Arina Selivanova 2021-07-01 Alpina 1639.000000 agg_sutochno.ru 63 4.0 Create a new column "is_loyal" through the lambda function, in which you put the value "True" if duplicates are found in the "name" column. If not put a "False"

df['is_loyal'] = df.duplicated(subset='name', keep=False).apply(lambda x: 'True' if x else 'False')

Questions about programming?Chat with your personal AI assistant