Generation

generate functionWed, 01 Feb 2023

There is a Pandas dataframe: song performer chart_debut peak_position worst_position time_on_chart consecutive_weeks 261636 Stupid Cupid Connie Francis 1958-08-02 17 72 12 11.0 46383 Chantilly Lace Big Bopper 1958-08-02 6 40 18 17.0 46384 Chantilly Lace Big Bopper 1958-08-02 6 40 19 18.0 46385 Chantilly Lace Big Bopper 1958-08-02 6 40 20 19.0 46386 Chantilly Lace Big Bopper 1958-08-02 6 40 21 20.0 Write a function that will group all rows by the performer column (so that no duplicates are left), and all corresponding values of this column are written through the "," sign into a new column hits

def group(df): return df.groupby(['performer'])['song'].apply(', '.join).reset_index()

Questions about programming?Chat with your personal AI assistant