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

import pandas as pd df = pd.DataFrame({ 'user_id': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], 'name': ['Ksenia Rodionova', 'Ulyana Selezneva', 'Konstantin Prokhorov', 'Petrov Vladimir', 'Arina Selivanova', 'Svetlana Kuznecova', 'Evgeniy Laptev', 'Ivan Ryzhkov', 'Sidorov Nikolay', 'Nikolay Ivanov', 'Natalya Volkova', 'Maksim Petrov', 'Maksim Petrov', 'Viktor Fomichev', 'Ulyana Selezneva'], 'date': ['2021-07-01', '2021-07-01', '2021-07-01', '2021-07-01', '2021-07-01', '2021-07-02', '2021-07-02', '2021-07-02', '

Questions about programming?Chat with your personal AI assistant