I have a dataframe of some information about some artists, their albums, and their tracks.
df = pd.DataFrame({'Artist': ['A', 'A', 'A', 'B', 'B', 'C', 'C', 'C', 'C', 'D', 'E'], 'AlbumId': [201, 201, 451, 390, 390, 272, 272, 698, 698, 235, 312], 'TrackId': [1022, 3472, 9866, 6078, 2634, 3411, 8673, 2543, 5837, 9874, 1089]})
Artist A has 2 albums(201 and 451), with one having 2 tracks(1022 and 3472) and 1 having 1 track(9866).
Artist B has 1 album(390) with 2 tracks(6078 and 2634).
Artist C has 2 albums(272 and 698), with each album having 2 tracks.
Artist D has 1 album(235) with 1 track(9874).
Artist E has 1 album(312) with 1 track(1089).
I want to find the artists who have more than 1 album, and get the rows of these artists accordingly. My desired output looks like this:
I have tried:
groupedArtists = data.groupby(['ArtistId', 'AlbumId']).filter(lambda group: (group.AlbumId.nunique() > 1))
But it seems not to work as expected.
Could someone please help me out? I appreciate it!