Generation

generate functionWed, 01 Feb 2023

There is a Pandas dataframe: performer hits chart_debut time_on_chart consecutive_weeks 8478 Taylor Swift Fifteen, Fearless, London Boy, Teardrops On My... 2008 14299 11880.0 3819 Imagine Dragons Radioactive, Natural, Believer, Thunder, On To... 2012 11101 9304.0 2674 Ed Sheeran Thinking Out Loud, Photograph, Sing, Don't, On... 2014 10685 10039.0 9590 The Weeknd Starry Eyes, Save Your Tears, Acquainted, Blin... 2022 9429 6713.0 5812 Mariah Carey Without You/Never Forget You, Don't Forget Abo... 1994 8735 6616.0 5749 Madonna Like A Prayer, Erotica, Vogue, Lucky Star, Cau... 1989 8391 7534.0 Write a function divide_decade(df, decade) which, when a decade is specified, will perform the appropriate filter of the chart_debut column on the grouped Performer column. for example divide_decade(df, '1980-1990') 5749 Madonna Like A Prayer, Erotica, Vogue, Lucky Star, Cau... 1989 8391 7534.0

import pandas as pd df = pd.DataFrame(data, columns=['performer', 'hits', 'chart_debut']) def divide_decade(df, decade): return df[(df['chart_debut'] >= int(decade[0:4])) & (df['chart_debut'] <= int(decade[5:9]))] divide_decade(df, '1980-1990')['performer']

Questions about programming?Chat with your personal AI assistant