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 Find the rows in the dataview where the values in the name column are duplicated. Create a new dataview in which the first row of the duplicate and all subsequent ones will be added. Sort the name column in ascending order Example: name Ksenia Rodionova Artur Petrov Ivan Sidorov Ksenia Rodionova Result: name Ksenia Rodionova Ksenia Rodionova

df = pd.DataFrame([['Ksenia Rodionova', 'Artur Petrov', 'Ivan Sidorov', 'Ksenia Rodionova']]).T df.columns = ['name'] df.drop_duplicates(keep = 'first', inplace = True) df.sort_values(by = 'name', ascending = True)

Questions about programming?Chat with your personal AI assistant