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 that groups the Performer lines by decade (for example, 1996 is 1990-2000)
import pandas as pd import numpy as np df = pd.DataFrame({'name': ['Taylor Swift', 'Imagine Dragons', 'Ed Sheeran'], 'year': [2008, 2012, 2014]}) def decade_equals(year): return year // 10 * 10 df.groupby(decade_equals)['name'].apply(list)